?
Solved

Using wscript.shell to launch an app from VBScript

Posted on 2004-03-24
5
Medium Priority
?
1,638 Views
Last Modified: 2008-02-26
hi guys,

Ive added a script behind a button on an Outlook form that launches an app if the Save & Close button is clicked. The problem is, the Run command fails on the wscript.shell object. It seems to be an issue with using a spae in the run string. ie. if I put "C:\temp\app.exe" it is fine, but if I put the app in temp 2 and use "C:\temp 2\app.exe" it just opens up the temp folder as if it truncated my run statement ! Here is my code...

Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "C:\temp 2\notepad.exe"
Set wshShell = Nothing

...doesnt work but...

Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "C:\temp\notepad.exe"
Set wshShell = Nothing

...does

Im running on Windows 2000 and Outlook 2002.
0
Comment
Question by:adders99
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10668693
try adding extra qoutes:

wshShell.Run ""C:\temp 2\notepad.exe""
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 200 total points
ID: 10668717
try this instead:

Dim wshShell
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run Chr(34) & "C:\temp 2\notepad.exe" & Chr(34)
Set wshShell = Nothing
0
 

Author Comment

by:adders99
ID: 10668792
Tried that one and got 'expected end of statement'
0
 

Author Comment

by:adders99
ID: 10668804
tried your second one and it worked a treat. Many thanks ! Any idea why it works like that ?
0
 
LVL 28

Expert Comment

by:vinnyd79
ID: 10668821
the chr(34) puts qoutes around the string,otherwise wshShell will think anything after the spaces are parameters.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 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