none
Global macro in Word Startup Folder RRS feed

  • Question

  • Hi,
    I have done a macro to convert documents from old styles to new styles. I  found on the web that we can put the macro in a global folder (word startup folder). So, I have tried to configure it but I have experienced many problems. In the .dot file, a commandbar button is added when you open the file (Document_Open events). This doesn't work for some users. Also, even if the commandbar button is there, depending of the document that is activate, when I click on it, something, I get a message that say "File not found". It's like if the macro is inside another instance of Word but there is only one instance. Then, if I select another file in the same instance and click on the button, it works (userform is displayed). The function is public. I don't know if there is something else to do? The tool is to deploy to a lot of users. Does anyone have an idea how to get a macro that works with all documents in the same instance? Is there a better approach? I plan to copy the file on a network location that will be specific for each office (local macro). So, this will help for the maintenance.
    Thank you,
    Alex

    Macro inside ThisDocument class module:

    Private Sub Document_Open()

        Dim cmdBar As CommandBar
        Dim cmdBarButton As CommandBarButton

        For Each cmdBar In Application.CommandBars
            If cmdBar.Name = "Word Tools" Then
                cmdBar.Delete
            End If
        Next cmdBar
       
        Set cmdBar = Application.CommandBars.Add("Word Tools")
       
        cmdBar.Visible = True
        cmdBar.Enabled = True
        cmdBar.Position = msoBarTop
       
        Set cmdBarButton = cmdBar.Controls.Add
        With cmdBarButton
            .Style = msoButtonCaption
             .Caption = "Button"
             .Tag = "Styles"
             .OnAction = "MacroConvertStyles"
        End With
       
    End Sub

    Private Sub Document_Close()

        On Error Resume Next
        Set cmdBar = Application.CommandBars("Word Tools")
        If Not cmdBar Is Nothing Then
            cmdBar.Delete
        End If
       
    End Sub

    Macro that is in a standard module:

    Public Sub MacroConvertStyles()

         frmWordTool.Show
       
    End Sub


    • Edited by SLIVED Wednesday, March 14, 2012 1:59 PM
    Tuesday, March 13, 2012 5:19 PM

Answers

All replies

  • If you want the global template to run on systems with Word 2007 or Word 2010, the template format needs to be dotm, meaning it has macros.


    Kind Regards, Rich ... http://greatcirclelearning.com

    Tuesday, March 13, 2012 9:01 PM
  • Hi Rich,

    If we have computers with Excel 2003 and others computers with Excel 2010, can I put 2 files in the same folder (a .dot and a .dotm) or I have to create a standard folder for Excel 2003 and another one for Excel 2010?

    For the commandbar button, do you have an idea why I get sometimes many buttons named "Word Tools" in the same word. It's like the code above (in Document_Open event) is not executed all the time.

    Thanks,
    Alex

    • Edited by SLIVED Wednesday, March 14, 2012 2:01 PM
    Wednesday, March 14, 2012 1:58 PM
  • Hi Alex,

    <<It's like the code above (in Document_Open event) is not executed all the time.>>

    I tested on my side and didn't encounter the problem. I think that you didn't set the  dot file's path correctly. You should add the global macro file's path to the Template and Add-Ins dialog.  For more details, please refer to this article:

    http://office.microsoft.com/en-us/word-help/deploy-your-word-macros-from-a-central-location-HA001087294.aspx

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Bruce Song Monday, April 2, 2012 6:12 AM
    Friday, March 16, 2012 9:00 AM