I am trying to resolve an error code in my VBScript file that is occurring in the code below when I use the send keys method. I am calling this .vbs file from a batch file that has a parameter that I store here as the variable filename.
Here is my .vbs file:
Set args = WScript.Arguments
arg1 = args.Item(0)
Dim filename
filename = ""&arg1&""
WshShell.Run("C:\root\bin\root.exe")
WshShell.AppActivate "Administrator: Command Prompt"
WshShell.SendKeys ".x analysis.C"
WshShell.SendKeys ".x double_gaus.C"
WshShell.SendKeys "c1->SaveAs("&filename&.pdf")"
WshShell.SendKeys ".q"
WScript.Quit 1
The error code coming out of the command prompt window when the batch file proceesds into the .vbs file is:
C:\...\Root_VBS_Script_1.vbs(12, 46) Microsoft
VBScript compilation error: Expected end of statement
What is the problem in my code? And are there any other problems?
Use & to concatenate the strings. You missed that in line 12:
WshShell.SendKeys "c1->SaveAs("&filename&.pdf")"
should be
WshShell.SendKeys "c1->SaveAs("&filename&.pdf&")"