|
-
Aug 21st, 2008, 10:04 AM
#1
Thread Starter
New Member
[RESOLVED] Trigger Macro from add in (vs 2003)
Hello!
I have an add-in (written in vs 2003) that changes the default template (normal.dot) to a custom one (start.dot) when Word starts. The problem is that the macro in start.dot isnt triggered. Is there a way to force it to trigger?
code:
doc.AttachedTemplate = strPath
thanx!
/Dave
-
Aug 21st, 2008, 04:24 PM
#2
Re: Trigger Macro from add in (vs 2003)
it should work if you put your code in document new event in thisdocument code pane
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 22nd, 2008, 01:36 AM
#3
Thread Starter
New Member
Re: Trigger Macro from add in (vs 2003)
I change the template in the WindowActivate event. When I start Word, the template has changed, but the macro isn't running. Isn´t there something similar to RunAutoMacro but for custom macros?
Code:
Public Sub act(ByVal doc As Word.Document, ByVal wn As Word.Window) Handles appWord.WindowActivate
doc.AttachedTemplate = strPath
End Sub
Last edited by david e; Aug 22nd, 2008 at 03:33 AM.
-
Aug 22nd, 2008, 04:46 AM
#4
Thread Starter
New Member
Re: Trigger Macro from add in (vs 2003)
I solved it!
I took a closer look at the macro, and it was triggered at the event Document_New(). So i used the doc.RunAutoMacro(Word.WdAutoMacros.wdAutoNew) to force the Document_New() function to run.
Thanks for your help! It got me thinking in new directions. The code is now:
Code:
Public Sub act(ByVal doc As Word.Document, ByVal wn As Word.Window) Handles appWord.WindowActivate
doc.AttachedTemplate = strPath
doc.RunAutoMacro(Word.WdAutoMacros.wdAutoNew)
End If
-
Aug 22nd, 2008, 05:32 AM
#5
Re: Trigger Macro from add in (vs 2003)
if you declare application with events in your addin, all application events can have code
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|