Calling a .vbs script from Excel VBA

I only want to add to Alex' answer, that in some environments the object must be created in the following way:

set scr = CreateObject("MSScriptControl.ScriptControl")

If Alex adds this to his answer, I will delete this one.


To run a file:

Shell "wscript c:\null\a.vbs", vbNormalFocus

replacing wscript with cscript if the VBS wants to use the console.

Or you can add a reference to the Microsoft Script Control and interact with the VBScript runtime directly to execute VBS code, procedures etc;

Dim scr As ScriptControl: Set scr = New ScriptControl
scr.Language = "VBScript"
scr.AddCode "sub T: msgbox ""All Hail Cthulhu"": end sub"
scr.Run "T"

Tags:

Vbscript