Running VBScript script file from Excel

pcc

Well-known Member
Joined
Jan 21, 2003
Messages
1,353
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
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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
 
Upvote 0
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).
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,177
Members
448,554
Latest member
Gleisner2

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
Back
Top