vba WScript.Shell run .exe file with parameter

后端 未结 2 635
不思量自难忘°
不思量自难忘° 2020-12-04 02:18

I am running a VBA macro from Word 2013. I\'m trying to run an executable file which requires an argument/parameter of a filename. For example, c:\\myfilefilter.exe f

相关标签:
2条回答
  • 2020-12-04 03:01

    this works for me (from MsAccess 2013 VBA)

    Dim wShell As New WshShell
    Dim wsExec As WshExec
        Dim cmdline As String
        cmdline = "notepad c:\somefile.txt"
        Debug.Print Now, cmdline
        Set wsExec = wShell.Exec(cmdline)
        Do While wsExec.Status = 0
            DoEvents
        Loop
        Debug.Print Now, "done"
    
    0 讨论(0)
  • 2020-12-04 03:06

    You could try this. Works for me.

    Const BatchFileName = "P:\Export.bat"
    

    Dim wsh As Object

    Set wsh = VBA.CreateObject("WScript.Shell")
    Dim waitOnReturn As Boolean: waitOnReturn = True
    Dim windowStyle As Integer: windowStyle = 1
    
    wsh.Run BatchFileName, windowStyle, waitOnReturn
    
    Kill BatchFileName
    
    0 讨论(0)
提交回复
热议问题