Getting “Invalid Procedure Call Argument” When i run call a Bat file from Subroutine

﹥>﹥吖頭↗ 提交于 2020-06-28 05:09:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!