Shell.Run with variables VBScript

This is what I need to start:
 shell.Run """\\CT01\Root\Visual_Documents\Vendors\V-ACACF-LAFAY\Checks\2014\42484.pdf"""
 
but I can't figure out how to encapsulate this in quotes.

I have tried:
  set shell = createobject("WSCRIPT.SHELL")
#1:
sThePDF = "\\CT01\Root\Visual_Documents\Vendors\V-" & VENDOR_ID & "\Checks\" & Check_YYYY & "\" & Check_Num & ".pdf"
#2:
Shell.Run sThePDF
#3:
Shell.Run ("sThePDF")
#4:
Shell.Run """\\CT01\Root\Visual_Doucments\Vendors\V-"" & VENDOR_ID & ""\Checks\"" & Check_YYYY & ""\"" & Check_Num & "".pdf""",1, True

None of these work. All give an error message.

I even tried:

 sThePDF = AddQuotes(sThePDF)
 sThePDF = AddQuotes(sThePDF)
 sThePDF = AddQuotes(sThePDF)
 Shell.Run sThePDF

No Error, but it just opens windows explorer.

Function AddQuotes(strInput)
    AddQuotes = Chr(34) & strInput & Chr(34)
End Function
BFanguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi, this has worked for me, so it should work this way.

Regards,

Rob.

VENDOR_ID = "123"
Check_YYYY = "2014"
Check_Num = "456"
Set objShell = createobject("WSCRIPT.SHELL")
sThePDF = "\\CT01\Root\Visual_Documents\Vendors\V-" & VENDOR_ID & "\Checks\" & Check_YYYY & "\" & Check_Num & ".pdf"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(sThePDF) = True Then
	objShell.Run """" & sThePDF & """",1, True
Else
	WScript.Echo "File not found: " & sThePDF
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dany BalianCTOCommented:
Rob's Answer is correct

just to explain string concatenation in vb:
dim mystring as string
mystring="dany"
assigns dany to mystring variable

now, if we want to add a double quotation inside the word, we just escape it by doubling it:
mystring="da""ny"
this will assign da"ny to the mystring variable.

so coming to your example, you just need your string to have a double quotation in the variable itself at the beginning and at the end, so you just need to insert 2 " at the beginning and at the end of your variable declaration.

so, if you look at your #1 code:
 
#1:
sThePDF = "\\CT01\Root\Visual_Documents\Vendors\V-" & VENDOR_ID & "\Checks\" & Check_YYYY & "\" & Check_Num & ".pdf"

your sThePdf variable's value would be:
\\CT01\Root\Visual_Documents\Vendors\V-ACACF-LAFAY\Checks\2014\42484.pdf

solution:
sThePDF = """\\CT01\Root\Visual_Documents\Vendors\V-" & VENDOR_ID & "\Checks\" & Check_YYYY & "\" & Check_Num & ".pdf"""

your sThePdf variable's value would become:
"\\CT01\Root\Visual_Documents\Vendors\V-ACACF-LAFAY\Checks\2014\42484.pdf"
0
BFanguyAuthor Commented:
thanks guys... forest for the trees stuff...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.