Solved Wscript.Shell > RUN, getting the syntax right (2 Viewers)

Isaac

Lifelong Learner
Local time
Today, 15:48
Joined
Mar 14, 2017
Messages
8,738
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!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:48
Joined
Oct 29, 2018
Messages
21,358
Hi. This worked for me.
Code:
CreateObject("WScript.Shell").Run """" & strFile & """"
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:48
Joined
Oct 29, 2018
Messages
21,358
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
 

Isaac

Lifelong Learner
Local time
Today, 15:48
Joined
Mar 14, 2017
Messages
8,738
Thanks!!! I'll try it first thing tomorow and report back.
 

Isaac

Lifelong Learner
Local time
Today, 15:48
Joined
Mar 14, 2017
Messages
8,738
Hi. This worked for me.
Code:
CreateObject("WScript.Shell").Run """" & strFile & """"
I used that and it worked - thanks for your help!
 

Users who are viewing this thread

Top Bottom