获取“无效的过程调用参数".当我运行时,从子程序中调用Bat文件 [英] Getting "Invalid Procedure Call Argument" When i run call a Bat file from Subroutine
本文介绍了获取“无效的过程调用参数".当我运行时,从子程序中调用Bat文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
找到以下代码:
Sub Button1_Click()
argh = Shell("C:\Users\YYYY\Desktop\test1.bat", vbNormalNoFocus)
End Sub
当我从子程序中调用Bat文件时,总是出现以下错误.还要附上屏幕截图.
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"
推荐答案
我们无法从Excel宏运行.bat文件,它将始终要求管理员权限.
We cannot run a .bat file from Excel macro , It will always ask for the Administrator permissions.
更好地创建一个.vbs文件,然后从.vbs文件中调用.bat文件.
Better Create a .vbs file and call the .bat file from .vbs file.
.vbs文件:将文件另存为runbatch.vbs
.vbs file : Save the file as runbatch.vbs
Set objShell = CreateObject("WScript.Shell")
objShell.run "C:\Users\YYYYYY\Desktop\test1.bat"
WScript.Quit
宏代码:在Excel VB编辑器中编写以下代码
Macro Code:In Excel VB Editor Write the below code
Sub Button1_Click()
shell "wscript C:\Users\YYYYYY\Desktop\runbatch.vbs",
vbNormalFocus
End Sub
这篇关于获取“无效的过程调用参数".当我运行时,从子程序中调用Bat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文