0

I have the following VBA:

Sub StartVbs(sVbsPathNmExt)   
 Shell "Explorer.exe """ & sVbsPathNmExt & """", 1    
End Sub

And the following VBScript in ParamPassTest.vbs:

MsgBox("Hello x" )    
WScript.quit

It displays a message "Hello x" when I call it like this from VBA:

Sub do_StartVbs()
  Call StartVbs("Z:\somepath\ParamPassTest.vbs")
End Sub

How do I pass that "x" in from VBA to VBS as an argument?

I tried both methods here and they either error or cause my anti-virus to close everything down: passing argument from vba to vbs

Rather than loosen my anti-virus rules, how do I pass in a parameter to a vbs from vba?

mountainclimber11
  • 1,339
  • 1
  • 28
  • 51
  • Does [this](https://stackoverflow.com/a/2806731/1188513) not answer your question? – Mathieu Guindon Aug 11 '17 at 20:39
  • So write it to a text file rather than an argument? Okay, I guess that work just as well. Thanks! – mountainclimber11 Aug 11 '17 at 20:44
  • As you responded on Slai's Answer: Your anti-virus is the problem, not the code... You need to whitelist your Macro-Spreadsheet and then you need to Whitelist your VBS File. I'm not sure which AV product you use but if it whitelists based on your file's hash, you might have to whitelist it every time you save it. – Steve Kline Aug 13 '17 at 16:39
  • @SteveKline - Yes, I was seeing if there was a way to get this done that didn't require messing with my AV. I guess writing to text or database is a good enough workaround. – mountainclimber11 Aug 14 '17 at 14:51

1 Answers1

2

You can try this in VBA:

Shell "WScript ""C:\path\1.vbs"" 123"

and this in 1.vbs:

If WScript.Arguments.Count > 0 Then MsgBox WScript.Arguments(0)
Slai
  • 22,144
  • 5
  • 45
  • 53