Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run a VBscript from within VB

Status
Not open for further replies.

rswarich

Technical User
Jun 7, 2001
7
US
I have a VBscript file that needs to be executed
from within a larger VB (Excel) macro.

In the past, have used something like:
Shell ("D:\CALROT1\shutdown.bat")
to run batch programs. This approach does not work
with a .vbs script.

What is the easiest way to execute a .vbs script
from within VB?

Thank you
 
The Windows Script Host facility provides two different script hosts:[ul][li]cscript.exe - for command-line scripts
[li]wscript.exe - for Windows GUI scripts[/ul]
Most of the scripting is the same for these two hosts, aside from user-interface differences.

The
Code:
Echo
method, for example, works in both hosts, working somewhat differently. The
Code:
Popup
method works the same way in both hosts.

In any case, it sounds like you want to start a shelled WSH script from within a VBA macro (in Excel).

Assuming your script is simple, has no command-line parameters, etc. you'd do something like:
Code:
Shell("wscript D:\CAROLT1\shutdown.vbs")
or
Code:
Shell("cscript D:\CAROLT1\shutdown.vbs")
The difference being where you want Echo-ed output going: to the command prompt window or to popup dialog boxes.
 
You can also just paste the code into your VBA code. The major difference is you can't use any wscript calls (ex. wscript.echo). This will work if you don't need the vbscript to run independently of the VBA program. Otherwise the solutions provided above should work great.

Dana Hallenbeck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top