VBScript to Run Excel Macros


How to execute Excel VBA Macros using VBScript. I have a Excel VBA and I want to Call the VBA Macro from VBScript.

Expert Asked on July 14, 2015 in VBA: Basics.
Add Comment
1 Answer(s)
Best answer

Here are the Steps to Call Excel VBA Macro using VBScript

  1. Create an Excel Macro file (MacroFile.xls)
  2. Open VBA Editor and Write the required Procedure to Run (ExampleMacro)
  3. Create VBScript (VBScriptCallMacros.vbs)
  4. Add the below VBScript in VBScriptCallMacros.vbs.
  5. Now run the VBScript File
  6. You can use Windows Task Scheduler to run the script at a specific Time.

Here are the VBScript:

This VBScript will open the Excel File (MacroFile.xls) and Execute the Macro (ExampleMacro) in the Excel Macro File.

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:TempMacroFile.xls")
objExcel.Application.Run "ExampleMacro"
WScript.Echo "Task Completed"

Here is the Explanation:

  1. Set objExcel = CreateObject(“Excel.Application”): Creates the Excel Application Object
  2. Set objWorkbook = objExcel.Workbooks.Open(“C:TempMacroFile.xls”): Opens the Excel VBA Macro File
  3. Visible=true : Show you the Excel Workbook
  4. Application.Run “ExampleMacro” : Run the Example Macro
  5. Application.Quit :Closes the Workbook and Quits the Excel Application
  6. Echo “Task Completed”: Show you the Popup Message once executed the above macro
  7. Quit: Quits the Script file


Keymaster Answered on July 14, 2015.
Add Comment
  • Found this useful?

    Please share using the share button above.

    If you found the answer is best answer for your question, Please mark as 'best answer' by clicking on the right tick mark icon at the left side of the answer.

    Found the answer useful and wants to credit the user, then vote the answer (vote up).

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.