none
Passing Variables Between Global Macro and Template Macro RRS feed

  • Question

  • I have a global macro in the startup directory with functions that store answers to variables, such as: 

    Public Function GetBranch() As String
        GetBranch = "Atlanta"
    End Function

    I want to retrieve that variable in the template project and have used the following code in Word 2002 and it works fine, but it just closes Word 2010.  Please help. 

        GetBranch = Application.Run("GetBranch")

     

     

    • Moved by Mike Feng Monday, September 5, 2011 2:04 AM Word (From:Visual Basic General)
    Friday, September 2, 2011 6:11 PM

Answers

  • Just thought of something else ... what't the format of your global template? dot or dotm?  Try inserting the macro in a dotm global template file.
    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by Liliane Teng Thursday, September 15, 2011 7:46 AM
    Monday, September 5, 2011 3:24 AM
  • Hi Shell

    In addition to Rich's thoughts on the matter, I'm wondering if there may be a problem with your Normal.dot template or the template you're loading as a global add-in. If these are coming forward from Word 2002 they've probably been around for quite a while? Maybe they've accumulated some "dreck" that Word 2010 can't deal with.

    You might try:

    1. Rename Normal.dot to NormalOLD.dot
    2. Start Word. This should generate a clean copy of Normal.dotm
    3. Now test your scenario with a macro in this new Normal.dotm
    4. If it doesn't work, create a new template (.dotm) with the sample function and save that in Startup. Move the old template out of startup. Start Word again and test.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Liliane Teng Thursday, September 15, 2011 7:46 AM
    Wednesday, September 7, 2011 11:14 AM
    Moderator

All replies

  • Hi Shell,

    Welcome to the MSDN Forum.

    I have moved this thread to more appropriate forum for better support.

    Best regards,


    Mike Feng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 5, 2011 2:04 AM
  • There must be some other issue in your system or in your code because I just tested the code you specified with Office 2010 on a Windows XP system and it returned "Atlanta".

    Are you up-to-date on your Office version and what version of Windows are you using?

    Have you tried some more extensive error trapping in your code to find what's actually causing Word 2010 to hang?

    If you can post more of the actual code, maybe someone can spot the issue.


    Kind Regards, Rich ... http://greatcirclelearning.com
    Monday, September 5, 2011 3:13 AM
  • Just thought of something else ... what't the format of your global template? dot or dotm?  Try inserting the macro in a dotm global template file.
    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by Liliane Teng Thursday, September 15, 2011 7:46 AM
    Monday, September 5, 2011 3:24 AM
  • Hi Shell21,

    I reproduced this issue on my side. This scenario does not happen with Word2010. I insert this global macro in the Normal project module. Then I create a new template project, and insert a new module with below code:

    Sub test()
    Dim GetBranch
    GetBranch = Application.Run("GetBranch")
    MsgBox GetBranch
    End Sub
    

    When I run test(), I could retrieve variable GetBranch, and Word2010 does not close. Is my understanding correct? Where do you put the global macro?

    If you have any concerns, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 7, 2011 8:55 AM
  • Hi Shell

    In addition to Rich's thoughts on the matter, I'm wondering if there may be a problem with your Normal.dot template or the template you're loading as a global add-in. If these are coming forward from Word 2002 they've probably been around for quite a while? Maybe they've accumulated some "dreck" that Word 2010 can't deal with.

    You might try:

    1. Rename Normal.dot to NormalOLD.dot
    2. Start Word. This should generate a clean copy of Normal.dotm
    3. Now test your scenario with a macro in this new Normal.dotm
    4. If it doesn't work, create a new template (.dotm) with the sample function and save that in Startup. Move the old template out of startup. Start Word again and test.


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Liliane Teng Thursday, September 15, 2011 7:46 AM
    Wednesday, September 7, 2011 11:14 AM
    Moderator
  • Hi Shell21,

    Would you mind letting us know the situation on your side now? If you have any concerns, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, September 13, 2011 8:24 AM