Vbscript from Command Bar Button

D

DaveChoiceTech

I have written an extensive vbscript that I would like to run from a
command button. Do I have to rewrite it in VBA or is there some way to
call vbscript in a macro?
 
G

Guest

If you save your VBScript to a .vbs file, you can run that file using the
ShellExecute function from the Win32API. Add this declaration in one of your
modules:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String _
, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
nShowCmd As Long) As Long
Public Const conSwNormal = 1

Then just call the function like this, passing the file name of your script:

ShellExecute 0, "open", "C:\Documents and
Settings\ericl\Desktop\myscript.vbs", vbNullString, vbNullString, conSwNormal

I'd recommend converting your VBScript to VBA anyway, if you can.
 
D

DaveChoiceTech

Thanks a lot Eric. I don't know how you have the time to follow these
groups but I'm glad you do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top