There are numerous instances where one stores the word document format as a Microsoft Word template. When the user opens the document (using the template), some macro needs to be executed. This can be achieved by RunAutoMacro Method of Word VBA
Sub Run_Macro_In_WordDocument()
Dim oWD As Word.Document
Set oWD = Documents.Add("c:\dcomdemo\sample.dot")
oWD.RunAutoMacro wdAutoOpen
End Sub
Here a new document is open based on the Sample.dot template and once the document is open the AutoOpen macro is fired
RunAutoMacro Method can be used to execute an auto macro that's stored in the specified document. If the specified auto macro doesn't exist, nothing happens
On the other hand, if a normal macro (not auto open etc) needs to be executed, Run method can be used
Application.Run "Normal.FormatBorders"
Where would you place the code for this? In the .dot template or elsewhere?
ReplyDeleteK