Solved Wscript.Shell > RUN, getting the syntax right (1 Viewer)

Isaac

Lifelong Learner
Local time
Today, 10:27
Joined
Mar 14, 2017
Messages
10,006
I'll admit I'm using VBScript, but am posting this in this forum because ... I know a lot of people use Access VBA to run out a wscript.shell line of code anyway, so hope you'll forgive me on that.

So, in VBScript, simply trying to shell open a file - as if the user had double clicked on it.

I saw this example:
CreateObject("WScript.Shell").Run("""C:\Program Files\my_html_files\file.htm""")
(note there are 3 double quotes on either side of that path).

But I have a variable path, so I have to pass in the variable. (And it might include spaces).

I figured OK, one out of those 3 double quotes, is the quote for the literal string. If I pass in a String variable, I can lose those. Which leaves two.

When I did this:
Code:
dim strRun
strRun = chr(34) & chr(34) & strFullPathToDatabaseFolder & "\Reconciliation_fe.accdr" & chr(34) & chr(34)
CreateObject("WScript.Shell").Run(strRun)
... the result was no error, but, as soon as the VBScript runs, it opens the This PC window (!?!?) Cannot explain that one ......

Anyway, what's the correct syntax to pass in, given that I have a string variable, which is a full path to an accdr file, and it might have spaces.
Thanks for looking!
 
Hi. This worked for me.
Code:
CreateObject("WScript.Shell").Run """" & strFile & """"
 
Hi. This worked for me.
Code:
CreateObject("WScript.Shell").Run """" & strFile & """"
This also worked:
Code:
strFile = """c:\foldername\filename.accdb"""
CreateObject("WScript.Shell").Run strFile
 
Thanks!!! I'll try it first thing tomorow and report back.
 

Users who are viewing this thread

Back
Top Bottom