从VBA调用.exe,但程序无法正常运行

时间:2017-07-31 18:03:37

标签: python vba outlook exe

我写了一个python脚本来从网站上抓取数据表并输出到csv。然后我使用cx_freeze将python脚本转换为.exe。当我手动运行.exe时,它会按预期执行,但是,当我从outlook运行下面的代码时,永远不会创建csv。也没有错误弹出。

Dim wsh As Object, x As Integer
Set wsh = VBA.CreateObject("Wscript.Shell")
x = wsh.Run("cmd /c C:\Users\username\Desktop\Lindner_Scrape\build\exe.win32-3.6\Scrape.exe", 1, True)

1 个答案:

答案 0 :(得分:0)

您需要创建批处理文件。在其中编写命令并执行批处理文件。

Sub bat()
Dim batch, fso As Object
Dim path As String
path = "C:\Users\username\Desktop\Lindner_Scrape\build\exe.win32-3.6\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set batch = fso.CreateTextFile(path & "Scrape.bat", True)
batch.writeline "cd " & path
batch.writeline "Scrape.exe"
batch.Close

Shell path & "Scrape.bat", 1
End Sub