I think the easiest option is to save the .bas file with the .vbs extension and change your code to VBScript; then run it under Windows Script Host (WSH). Keep in mind that in VBA under Excel you have access to a number of built-in objects; in VBScript under WSH, you will need to create or access these objects yourself (see this answer ) using the CreateObject or GetObject . (WSH has its own set of built-in objects.) In the case of Excel, you need to start with:
Dim xlApp Set xlApp = CreateObject("Excel.Application")
Keep in mind that in VBScript variables are not of type, therefore all statements, such as:
Dim i As Integer Dim wks As Excel.Worksheet
you must delete the As clause:
Dim i Dim wks
For exact information on the differences between them, see
INFO: Visual Basic for Applications Features Not in VBScript and
INFO: VBScript Functions Not in Visual Basic for Applications .
VBA has a built-in IDE and debugger that you donโt have when running code under WSH, but you can use Visual Sudio to debug the Script file. (If you cannot install VS 2015 Community Edition, the integrated shells of Visual Studio -
2013 ,
2012 ,
2010 will also be integrated.
Debug your scripts by invoking them from the command line as follows:
cscript yourscript.vbs
or
wscript yourscript.vbs
If you have Office 2007 or earlier installed, you can use the Microsoft Script editor for debugging; No need to download and install VS. However, VS is much more powerful than Microsoft Script Editor and the VBA debugger.
source share