how to execute a VBScript file from a VB6 subroutine?
Hello,
I was wondering if anyone could share with me the VB6 code that would execute a VBScript file named
test.vbs
in the subdirectory
D:\test\
thanks in advance,
david
[193 byte] By [
dgr7] at [2007-11-11 10:14:05]

# 2 Re: how to execute a VBScript file from a VB6 subroutine?
I would use the ShellExecute API function call:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpszOp As String, _
ByVal lpszFile As String, ByVal lpszParams As String, _
ByVal LpszDir As String, ByVal FsShowCmd As Long) _
As Long
Sub RunScriptFile()
Const SW_SHOWNORMAL = 1
ShellExecute 0&, "Open", "D:\test\Test.vbs", "", "D:\test\", SW_SHOWNORMAL
End Sub
# 3 Re: how to execute a VBScript file from a VB6 subroutine?
Paul,
hello,
how do I use your above code snippet in a Form?
When I add it to the Form code I already, and put it at the top of the code outside of any Subroutines, and then try to run the code I get the error:
Compile error:
Constants, ...etc...and Declare statements not allowed as Public members of object modules.
Can you give me an example of what the "surronding" code looks like that goes with this code snippet you provided?
thanks in advance,
david
dgr7 at 2007-11-11 17:25:01 >

# 4 Re: how to execute a VBScript file from a VB6 subroutine?
If the API function call declare is in a Form it must be declared as Private. Placing Private in front of the Declare should resolve the compile error.