[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Shell.Run with variables VBScript

Posted on 2014-08-27
3
Medium Priority
?
260 Views
Last Modified: 2014-08-28
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
0
Comment
Question by:BFanguy
3 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 1200 total points
ID: 40289313
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
 
LVL 11

Assisted Solution

by:Dany Balian
Dany Balian earned 800 total points
ID: 40289851
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
 

Author Closing Comment

by:BFanguy
ID: 40290215
thanks guys... forest for the trees stuff...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question