excel

Run a Macro at a Specific Time

Sub ImportModules()

Debug.Print "test"

End Sub



Private Sub Workbook_Open()

    Application.OnTime Now + TimeValue("00:00:01"), "domeprog.ThisWorkbook.ImportModules"

End Sub

The code above will run the macro called ‘ImportModules’ one second after the workbook is opened.

If the macro is located in a class module or in ThisWorkbook class, then you will need to call out the library + class + member name. You can find this info in the Object Browser (press f2 or click on icon) and then typing your macro name in the search box.

Object browser

If the macro is located in a regular module, then you can just call the member name like this

Application.OnTime Now + TimeValue("00:00:01"), "ImportModules"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s