none
Word 2007 not executing macros when creating new documents from a Word 2003 template RRS feed

  • Question

  • I have a series of Word 2003 templates. The templates all contain ActiveX checkboxes, textboxes, etc. and VBA code. They work just fine on Word 2003. When a user with Word 2007 double clicks on the template, a new document is created, and all the text and ActiveX object appear on the document, but the macro code behind does not run so drop down boxes are not populated, etc. When the template is opened directly in Word 2007, everything works fine. Documents saved using 'Save As' work fine after the template is opened directly. The templates have a valid timestamped signature, and exhibit this behavior both in and out of trusted locations. I'd like for Word 2007 users to be able to double click on the template and create a working document. Has anyone else encounted this issue, or have a suggestion on what to try next? Thanks!
    • Edited by kfleschner Monday, April 18, 2011 1:48 PM forgot word
    Monday, April 18, 2011 1:47 PM

All replies

  • What name have you assigned to the macros?  It needs to be AutoNew for it to run when a document is created from the template.


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "kfleschner" wrote in message news:5208b7d4-5dff-4ae4-8966-898cfe13c99d@communitybridge.codeplex.com...

    I have a series of Word 2003 templates. The templates all contain ActiveX checkboxes, textboxes, etc. and VBA code. They work just fine on Word 2003. When a user with Word 2007 double clicks on the template, a new document is created, and all the text and ActiveX object appear on the document, but the macro code behind does not run so drop down boxes are not populated, etc. When the template is opened directly in Word 2007, everything works fine. Documents saved using 'Save As' work fine after the template is opened directly. The templates have a valid timestamped signature, and exhibit this behavior both in and out of trusted locations. I'd like for Word 2007 users to be able to double click on the template and create a working document. Has anyone else encounted this issue, or have a suggestion on what to try next? Thanks!


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Monday, April 18, 2011 8:01 PM
  • Hello,

    I have experienced under certain circumstances (don't remember exactly which) the AutoNew maco does not get called, but the event callback Document_New is called.

    If you are not using Document_New, go to the "ThisDocument" code module and select 'Document' in the dropdown list to the left above the code editing area. Then in the right dropdownbox select New. Write some code and see if it gets called. If you have both AutoNew and Document_New in your template, one of them should get called.

    Regards,
    Lars-Eric

    Monday, April 18, 2011 8:39 PM
  • The code is being called from Document_New() which calls a sub which calls other subs and so on. What is so fustrating is that the failure is only seen when created new documents from the template in Word 2007, even when the template is in a trusted location and the code certificate has been accepted as a trusted publisher. I'll try the AutoNew on the next revision and see if that helps. Any other ideas on why 2007 and not 2003 would be having a problem with it?

    Thanks!

    Monday, April 18, 2011 8:47 PM
  • I tried both the Document_New() and AutoNew() subs and both produced the same result. New documents created from the 2003 template in 2007 do not run the macro. I'm wondering if it might have to do with trusted locations? If the new document is created from a template, then it doesn't have a location yet and therefore can't be from a trusted location. Does that make any sense?

    Monday, April 18, 2011 9:06 PM
  • Hi kfleschner

    "Trusted location" refers to where the "code container" (in this case, the template) is stored. So theoretically the code should run if the template is in a trusted location.

    It's been a while since I made the migration you're struggling with, so I can't remember exactly what I did / have done, but...

    1. For a test, if you take a document without any ActiveX controls, link this to the template in Word 2003 (Tools/Templates and Add-ins, the top half of the dialog box, click "Browse" and select the template file), then double click that on a word 2007 machine, do the macros trigger? (Yes, you'll get error messages, but this is just to determine whether the issue is the ActiveX controls.)

    2. If the template is saved in Word 2007 in the dotm file format, then closed and double-clicked does that make any difference?

    3. Do you see the same problem if the user goes over the "New" command in the Office button (the "pizza" that's replaced the File menu)? If yes, start Word 2007 in Safe Mode (hold down Ctrl when starting it) then try over the "New" menu. Does the behavior persist? (In this test, we're checking whether it's only double-click and secondly, whether it may be a setting in the Word installation.)


    Cindy Meister, VSTO/Word MVP
    Tuesday, April 19, 2011 6:08 AM
    Moderator
  • Hi Cindy,

    Tests 2 and 3 produced the same results. Saving the template as a .dotm didn't help, and creating a new document from the Word New menu both normally and in safe mode both produced documents which didn't execute the macros properly. I'll run test one tomorrow.

    Thanks for the test suggestions!

    Wednesday, April 20, 2011 8:56 PM
  • Hi kfleschner,

    I wonder if it could be a timing issue. You might experiment with inserting a 1 second delay before executing the subordinate subs.


    Regards
    Thursday, April 21, 2011 4:13 AM
  • Project has been delayed, so I'll have to get back to this in a few weeks.
    Tuesday, May 10, 2011 9:58 PM