I have this excel file which contains a macro in it. What i used to do is to open the excel file to run the macro… but now I’m trying to find a way to run the macro from a vbs file or .bat file if possible (to automate it).

I googled a bit and found out that i can run a vbs file from a .bat file, and hopefully from the vbs file i can call the macro function in the excel file. This is my only solution for now. If you guys could provide another alternative, all the better.

Additionally, this also may need to pass parameters to the vbs file. Its for the input for the macro, since i’m not using the excel GUI for macro input --as what i used to do-- key in the input from the macro GUI.

Create your macro as a Workbook_Open() macro and then all you need to do is execute the filename, it should automatically load excel. If you end with application.quit it will exit excel. Your only concern should be security levels and if Macros require authorization to run or are blocked entirely.

Private Sub Workbook_Open()
    x = MsgBox("Macro Function Here", vbOKOnly)
   application.quit
End Sub

You should read up on “Office Automation.”

The Office applications, such as Excel, expose a set of objects that you can use in VBScript. You start by creating an object (using the CreateObject method) that represents the application. You can then use the methods of that object to open your workbook and to run the macro:

..
set myExcel = CreateObject(Excel.Application)
set myWorkbook = myExcel.Worksheets.Open("Excel workbook with Macro.XLS")
myWorkbook.Run("Name of Macro")
..