none
Sendkeys is working only when triggered from macro and not from vb script RRS feed

  • Question

  • In  below macro, sendkeys are working only when macro fucntion ran from .xlsm.

    When macro called from vb script, sendkeys are not working.

    My intention with this macro is to open a notepad and save it and close regardless of the contents, this is for alignment issue with the data.

    Any help would be appreciated

    Sub Openclose()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Dim fso As Scripting.FileSystemObject
    Dim fsoFolder
    Dim fsoSubFolder
    Dim fsoFile
    Dim fsoPath
    Dim PATHHH
    Dim Filee, tt, oShell

    Set fso = CreateObject("Scripting.FileSystemObject")
    PATHHH = "C:\Users\Test\"
    fsoPath = PATHHH
    Set fsoFolder = fso.GetFolder(fsoPath)
    For Each Filee In fsoFolder.Files

        Debug.Print Filee.Path
        

        If InStr(Filee.Path, "textfile.TXT") Then
        Debug.Print Filee.Path
        tt = "Notepad.exe " & Filee.Path
        Call Shell(tt, 1)
        Set oShell = CreateObject("WScript.Shell")
        oShell.AppActivate "CD-1646.txt"
        Application.Wait (Now() + TimeValue("00:00:01"))
        oShell.SendKeys "^s"
        Application.Wait (Now() + TimeValue("00:00:01"))
        oShell.SendKeys "%{F4}"
        Application.Wait (Now() + TimeValue("00:00:01"))
        End If
    Next
    End Sub

    Tuesday, October 24, 2017 11:03 PM

All replies