【发布时间】:2021-09-29 16:22:52
【问题描述】:
我有upload.exe,应该通过excel中的按钮启动,但是当我从按钮启动时,出现错误:
method run of object iwshshell3 failed
我的代码
Sub upload()
Application.Calculation = xlCalculationManual
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim strProgramPath As String
Dim strProgramName As String
Dim strArgument As String
strProgramPath = "\upload.exe"
strProgramName = "upload.exe"
strArgument = Application.ActiveWorkbook.FullName
wsh.Run """" & strProgramPath & strProgramName & """ """ & strArgument & """", windowStyle, waitOnReturn
Application.Calculation = xlCalculationAutomatic
End Sub
文件夹中的文件排列如下:
directory:
-upload.exe
-table.xlsm
【问题讨论】:
-
strProgramPath & strProgramName将是\upload.exeupload.exe这很可能不是您想要的。检查Debug.Print """" & strProgramPath & strProgramName & """ """ & strArgument & """"并确保这是您要运行的正确路径。更改为strProgramPath = "C:\My\path\to\"并确保它以反斜杠结尾。
标签: excel vba excel-2010