在 VBA 中获取无效的外部程序错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25295221/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting Invalid outside procedure error in VBA
提问by Diego Gomez
I get this error (VBA in Excel): Invalid outside procedure
in the first chr(34)
我收到此错误(ExcelInvalid outside procedure
中的VBA):在第一个chr(34)
Shell (Chr(34)) & "C:\Python27\Scripts\pybot.exe" & Chr(34) & " " & Chr(34) & _
"C:\Users\cwr.Diego.Gomez\Desktop\main_test_suite\myTests\Diego.txt" & Chr(34))
Could somebody please try to explain why?
有人可以尝试解释为什么吗?
回答by Jan Rothkegel
You must put your line into a sub and not just place it in the editor alone.
您必须将您的行放入子文件中,而不仅仅是将其单独放置在编辑器中。
Try something like this:
尝试这样的事情:
Sub MySub()
Shell (Chr(34) & "C:\Python27\Scripts\pybot.exe" & Chr(34) & " " & Chr(34) & _
"C:\Users\cwr.Diego.Gomez\Desktop\main_test_suite\myTests\Diego.txt" & Chr(34))
End Sub
回答by dbmitch
The issue is as @Sifu says - you have an extra bracket
问题正如@Sifu 所说 - 你有一个额外的支架
But if you put everything in a string to start with it'll make it easier to see your syntax errors
但是如果你把所有的东西都放在一个字符串中,它会让你更容易看到你的语法错误
dim strCmd as string
strCmd = """C:\Python27\Scripts\pybot.exe"" " & _
"""C:\Users\cwr.Diego.Gomez\Desktop\main_test_suite\myTests\Diego.txt"""
Shell (strCmd)