Results 1 to 5 of 5

Thread: [RESOLVED] Trigger Macro from add in (vs 2003)

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    11

    Resolved [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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    11

    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.

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    11

    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

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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
  •  



Click Here to Expand Forum to Full Width