none
Add-in Tab disappeared and Trying to add a button to ribbon on a file! RRS feed

  • Question

  • Hi,

    Question 1:

    My organization is moving from Office 2003 to Office 2010. My macro executes from a button on the toolbar in Word 2003. When I initially opened the file in Word 2010, I saw the button on the Add-In tab but then the entire tab disappeared and I'm not sure why...

    I have been working on figuring out the security settings to ensure that the macro still works. I'm suspicious that this may be related. My current security settings are (and I think they need to stay this way): Enable all macros, and Allow documents on a network to be trusted.

    Question 2:

    I did try adding a new button and did so successfully but it appears to be tied to Word and not the file itself and I can't seem to find any documentation that illustrates how to do this.

    ****************

    FYI, the macro has to continue running in both environments until the transition is complete...which is likely to take the better part of a year and I have no control over this.

    Help on either question would be much appreciated as I'm down to the wire on this one (evidenced by the fact that its Saturday at 6pm)!!!

    Thanks so much,

    Jill

    Saturday, October 1, 2011 9:56 PM

Answers

  • Hi Jill

    Trusted locations can be granted by IT through the use of Group Policies. There's no reason your organisation can't use them, even if they don't want to give the users a way to set them. It makes perfect sense to have, at the very least, a Workgroup Templates network location for templates for the entire organisation.

    Is it certain that your toolbar button was NOT saved in the same document with the macro? That would explain why it suddenly "went missing". If it was saved in a globally loaded template (such as Normal.dot, which may have been replaced with a Normal.dotm since you first tested), for example?

    It is possible to add a CommandBar and CommandBarControl "on-the-fly". Something like:

    Dim cb as Office.CommandBar
    Dim ctl as Office.CommandBarButton
    Dim exists as Boolean
    Dim s as String
    s = "My Toolbar"
    Application.CustomizationContext = ThisDocument
    For Each cb in ThisDocument.CommandBars
      If cb.Name = s Then
        exists = True
        Exit For
      End If
    Next
    If Not exists Then
      Set cb = Application.CommandBars.Add(s)
      Set ctl = cb.Controls.Add(msoControlButton)
      ctl.Caption = "My Macroname"
      ctl.OnAction = "Macroname"
      ctl.Style = msoButtonCaption
    End If


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Jill Eilerts Monday, October 3, 2011 1:58 PM
    Monday, October 3, 2011 4:12 AM
    Moderator

All replies

  • Click on the File menu, then on Options and then in the Word Options dialog, click on Customize Ribbon and make sure that there is a check mark against the Add-Ins item in the right hand list.

    I would suggest that the Macro Security setting should be "Disable all macros with notification" 

    Having all macros enabled and trusting all documents on a network is not to be recommended.

    By default, there are a number of trusted locations in Word from where macros in templates will be enabled.  You can (judiciously) add other locations as necessary.

    There is only limited user customization of the Ribbon available via the user interface.  For serious customization, you will need to follow the method detailed on the following page of Greg Maxey's website:

    http://gregmaxey.mvps.org/Customize_Ribbon.htm


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    Saturday, October 1, 2011 10:56 PM
  • Hi Doug,

    Thanks for the response.

    I did check the normal location for the Add-In toolbar and it indicates that it is active.

    I totally agree with your comments regarding the security...I wanted to use "trusted locations" for my macro but unfortunately we do not have access to this functionality as it have been deemed for the use of administrators only within our organization. I hope that I can affect some change in this regard. The macro is actually stored on a network drive on more than 200 servers across the country.

    I had a thought that perhaps I can programmatically add the button on execution of the macro as its an autoopen macro, so this is what I will try next.

    Another other thoughts on this?

    Thanks,

    Jill

    Sunday, October 2, 2011 1:47 PM
  • Hi Jill

    Trusted locations can be granted by IT through the use of Group Policies. There's no reason your organisation can't use them, even if they don't want to give the users a way to set them. It makes perfect sense to have, at the very least, a Workgroup Templates network location for templates for the entire organisation.

    Is it certain that your toolbar button was NOT saved in the same document with the macro? That would explain why it suddenly "went missing". If it was saved in a globally loaded template (such as Normal.dot, which may have been replaced with a Normal.dotm since you first tested), for example?

    It is possible to add a CommandBar and CommandBarControl "on-the-fly". Something like:

    Dim cb as Office.CommandBar
    Dim ctl as Office.CommandBarButton
    Dim exists as Boolean
    Dim s as String
    s = "My Toolbar"
    Application.CustomizationContext = ThisDocument
    For Each cb in ThisDocument.CommandBars
      If cb.Name = s Then
        exists = True
        Exit For
      End If
    Next
    If Not exists Then
      Set cb = Application.CommandBars.Add(s)
      Set ctl = cb.Controls.Add(msoControlButton)
      ctl.Caption = "My Macroname"
      ctl.OnAction = "Macroname"
      ctl.Style = msoButtonCaption
    End If


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Jill Eilerts Monday, October 3, 2011 1:58 PM
    Monday, October 3, 2011 4:12 AM
    Moderator
  • Hi Cindy,

    Thanks for your input...very helpful. I am actually following up with my local IT department regarding adding trusted location. Given that local IT will always have to do a bit of set up for the macro to run properly across the country, I may employ this method but will do some testing to see what requires the least effort for the user and local IT.

    I did ultimately figure out how to tie the toolbar to the file....there's some curious rules on this in Office 2010! My file was a template and apparently you can't add an element to the menu to a template...you have to work with a regular doc file, then save as a template.

    Thanks for the code...I believe it will prove useful to ensure that the button appears in both Word 2003 and 2010.

    Cheers!

    Jill

    Monday, October 3, 2011 1:58 PM