We usually want our macro to run as soon as we open our document. To make this happen we use the 'Document_Open()' method which automatically runs any instruction inside this method.
Private Sub Document_Open()
MsgBox "Hello World!"
End Sub
It will depend on you if you want to make it public or private. Just make sure you have typed this code in the 'ThisDocument' Module so that it will run the command when you open the document file.
We can still use modules in creating your macro, but if you need the call the method in the 'ThisDocument' object to make it automatically run.
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment