1
votes

How can I get a Macro to run as soon as the file is opened?

I want to "Prefill" it from an external data source (Excel). I know how to fill the document but would like the Macro to run automatically

1

1 Answers

3
votes

Use the Document.Open event. You need to place the Document_Open() sub in the ThisDocument class module of your file. Example from MSDN:

Private Sub Document_Open() 
    MsgBox "This document is copyrighted." 
End Sub

or in your case something like

Private Sub Document_Open() 
    Call PreFillDoc
End Sub

It will only run if macros are already enabled though.