我尝试使用以下代码
Dim pthName As String
Dim Parms As String
Dim RpNo As Integer
Dim glngbr As Long
Dim PrtVw As String
pthName = "D:\Sample.exe"
RpNo = 1
PrtVw = "V"
glngbr = 84003
Shell pthName & Parms
我收到错误"运行时错误53"。
我尝试了没有参数的工作
Shell pthName
答案 0 :(得分:0)
你可以这样使用,
Shell "D:\Sample.exe" & " " & Param_1, Param_2
答案 1 :(得分:0)
试试这个:
Shell "D:\Sample.exe" & " " & RpNo & " " & PrtVw & " " & glngbr
答案 2 :(得分:0)
使用api shellexecute http://support.microsoft.com/kb/238245
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_HIDE As Long = 0
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_SHOWMAXIMIZED As Long = 3
Private Const SW_SHOWMINIMIZED As Long = 2
private Sub exec_program()
ShellExecute App.hInstance, "Open", "D:\Sample.exe", "Parms", "C:\", SW_SHOWNORMAL
End Sub
答案 3 :(得分:0)
您不需要使用Shell命令或ShellExecute。有一个更简单的解决方案:全局VBA.Command
对象包含您在调用exe文件时添加的任何字符串。例如,如果在命令行中输入myproject.exe hello world
,则VBA.Command
将包含字符串hello world
。
如果需要多个命令行参数,可以将它们全部放在由已知分隔符(例如/
)分隔的命令行上。然后你可以使用Split功能来分解它们。
阅读This。它将告诉您所有相关信息,包括如何在IDE中使用它而无需针对编译版本进行测试。