2017-07-31 58 views
0

我寫了一個python腳本來從網站上刮取數據表並輸出到csv。然後,我使用cx_freeze將python腳本轉換爲.exe。當我手動運行.exe時,它按預期執行,但是,當我從Outlook運行下面的代碼時,csv從不創建。沒有錯誤彈出。從VBA調用.exe,但該程序無法正常運行

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

檢查它沒有出現在您的文檔中。嘗試在Excel中更改工作目錄或在Python腳本中使用相對路徑。 –

+0

它沒有提出錯誤,那麼文件*就是*被創建的,你只是沒有想出它被寫入的位置。顯示你的.py文件的內容,這可能有助於確定問題的根源...... –

+0

Florent解決了它。它保存到我的文檔中(當手動運行時保存在當前目錄中)。 –

回答

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