December 3, 2018

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

6 thoughts on “Run Macro Automatically without Opening Excel File

  1. Hi Dinesh,
    This is very helpful, But How can I run this for multiple excel files with same macro

    Thank you

  2. Hi Sir,
    Can we open an excel file automatically through msoutlook calender function.
    If I have set a time like 4 pm, in my outlook calender, so it should open the file mentioned in the subject line/body of the reminder.

    Thank You

  3. Sir, I have written macros in VBA and I have scheduled them in the task scheduler. Now I want to edit the excel file remotely i.e., I have uploaded it on my drive and want to run the macros but the original file in my PC should also be overwritten once I make changes in the file on my drive. How is it possible?

  4. Hi,

    Your videos are very helpful.
    I am trying to create a macro to auto refresh AFO file, but macro is working correctly showing some errors, can you please help me to fix that.

  5. Hi ,
    I have copied data to excel the formatting is not getting refreshed until I manually press f2 and enter or double click on that cell .so to counter this issue I have created a macro that will press enter in all the cells of the given range, but the issue is if I use ObjExcel.Visible = False the code executes but the formating is not getting reflected.

Comments are closed.