Run Macro Automatically without Opening Excel File

How to run a macro without opening the Excel file using a Visual Basic Script. You may also refer to the video how to import data into Excel from a Word table.

Watch the training video below:

We first create a file called “myVBScript.vbs” using notepad. In this file we run the macro in Module1 using this line of code:

objExcel.Application.Run “‘C:\Users\takyar\Desktop\how-to-import-data-from-Word-tables-into-Excel-with-VBA.xlsm’!Module1.importTableDataWord”

After the Excel Application is launched, we execute the ‘importTableDataWord’ in module1 in file how-to-import-data-from-Word-tables-into-Excel-with-VBA.xlsm located on the desktop. Important to note is how path to the file is located. We use first double-quotes and then an apostrophe. The quotes are closed at the end but the apostrophe is closed after the Excel file extension ‘xlsm’.

This line of code does not allow alerts to be displayed so that no user intervention is required: objExcel.DisplayAlerts = False

The next line closes the apllication: objExcel.Application.Quit

The last line of code frees memory: Set objExcel = Nothing

Further reading:

How to Import Data from Word Tables into Excel with VBA