问题
Find the below code:
Sub Button1_Click()
argh = Shell("C:\Users\YYYY\Desktop\test1.bat", vbNormalNoFocus)
End Sub
When I run call a Bat file from Subroutine, I always get below error. Attached screen shot as well.
"Run time Error"
"Invalid Procedure call or argument"
回答1:
We cannot run a .bat file from Excel macro , It will always ask for the Administrator permissions.
Better Create a .vbs file and call the .bat file from .vbs file.
.vbs file : Save the file as runbatch.vbs
Set objShell = CreateObject("WScript.Shell")
objShell.run "C:\Users\YYYYYY\Desktop\test1.bat"
WScript.Quit
Macro Code:In Excel VB Editor Write the below code
Sub Button1_Click()
shell "wscript C:\Users\YYYYYY\Desktop\runbatch.vbs",
vbNormalFocus
End Sub
来源:https://stackoverflow.com/questions/52924559/getting-invalid-procedure-call-argument-when-i-run-call-a-bat-file-from-subrou