Batch Code (option 1)
I typically used this to simply call vbs from batch, no variables included.
@echo off
myVBSpath=\\UNC\path
set vbsFileName=myVBS.vbs
cscript "%myVBSpath%\%vbsFileName%"
pause
Batch Code (option 2)
I typically use this option when passing a variable from batch to VBS... including the variable name & value after the vbs file path and name.
@echo off
set myVBSpath=\\UNC\path
set vbsFileName=myVBS.vbs
cscript //NoLogo "%myVBSpath%\%vbsFileName%" /attachment: "%myAttachment%"
pause
Resulting Batch Error Message
Regardless of which option I use above, I get the following error message:
\\UNC\path\myVBS.vbs(11, 1) Microsoft VBScript runtime error: Argument not optional
VBS Code
Dim xlApp
Dim xlBook
'Dim attachmentFullName
'attachmentFullName = WScript.Arguments.Named("attachment")
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("\\UNCpath\myExcelFile.xlsm", 0, True)
xlApp.DisplayAlerts = False
xlApp.Run "myMacro" ', Cstr(attachmentFullName)
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
Troubleshooting
I do not require a variable to be passed to vbs, so batch code (option 1) should be the way to go, and its how I started. When I got the runtime error message above, I tried to pass a false variable using option 2 just to see if that provided the extra argument the cscript command is looking for. Unfortunately, option 2 gave the same error message.
This is a fairly straight forward batch script, so I'm really at a loss and feel like maybe I've just been staring at it too long, making it harder than it needs to be, and I'm just missing something simple.
Would any of you be kind enough to give me a fresh set of eyes and give me an idea of what is causing my runtime error?
Thank you!
myAttachmentas variable ?? i don't see it ??? - Hackooset myAttachment=1, just so it had an argument variable to pass to vbs (and adjusted my vbs to accept an argument). - TMYSub myMacro(t as string)-- just deleted(t as string)and was back up and running. - TMY