Running VBScript script file from Excel

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,345
I've just been upgraded to SAP4.7, and this version includes the ability to record and playback script (just like macro recorder in Excel!).
I would like to launch the playback of the recorded VBScript file (.vbs extension) from within Excel, Anyone have any code as a starter for 10?
Thanks
 

Some videos you may like

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
Here's one way -- with an API:

Code:
Option Explicit
Private 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 Sub testIt()
    On Error Resume Next
    ShellExecute 0&, vbNullString, "c:\vbscript.vbs", vbNullString, _
        vbNullString, vbNormalFocus
    On Error GoTo 0
    End Sub
 

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,345
Thanks. What's the application that vbs files should be associated with? I think it may be 'Microsoft (r) windows based script host', but I'm not sure. At present it is set to notepad, and your code above works OK except that it launches notepad!!
(I can't get '...script host' at the moment and my IT guys are looking into it).
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,028
I haven't changed anything on my computer related to the file association for .VBS. On checking the file association, it turns out to be WScript.exe in the system folder.
 

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,345
Thanks. I have Wscript.exe on my PC, when I try to run it, I get a message
'Access to the specified... is denied'. I suspect that this exe file is trying to get something from an area that I am not authorised to access... over to my IT department!
Thanks for your time
Regards
 

Watch MrExcel Video

Forum statistics

Threads
1,127,462
Messages
5,624,871
Members
416,063
Latest member
chaulon199

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top