Vbscript from Command Bar Button

  • Thread starter Thread starter DaveChoiceTech
  • Start date Start date
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?
 
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.
 
Thanks a lot Eric. I don't know how you have the time to follow these
groups but I'm glad you do.
 
Back
Top