【问题标题】:method run of object iwshshell3 failed对象 iwshshell3 的方法运行失败
【发布时间】: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


【解决方案1】:
...
Dim strProgramPath As String
Const ProgramName = "upload.exe"
Dim strArgument As String
'full path to program in workbook directory      
strProgramPath = ActiveWorkbook.Path & Application.PathSeparator & ProgramName
strArgument = Application.ActiveWorkbook.FullName

wsh.Run """" & strProgramPath & """ """ & strArgument & """", _
  windowStyle, waitOnReturn
...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2019-03-02
    相关资源
    最近更新 更多