• Macro Problem in Word 2007 (VBA / Office 2007)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Macro Problem in Word 2007 (VBA / Office 2007)

    Author
    Topic
    #433986

    I just got Office 2007 Beta 2 and I have a Word template that I want to use. As expected, the custom toolbars from this template appear inside of the Add-Ins
    ribbon. All of the macros work fine except for one. This macro allows the user to customize on the spot by adding a button to one of these custom
    toolbars. (There is another macro that allows the user to remove the same button.) In earlier versions of Word this macro will name the button with the
    exact name of the style that the user enters. This does not happen in Word 2007 however. Eventhough the added buttons function correctly and are placed inside the ribbon where you would expect, the caption is wrong; it always appears as “Apply Style Name.”

    Can this be fixed in Word 2007?

    Thanks, Jerry

    Here is the macro that adds a button:

    Sub AddButton()

    Dim eName As String

    eName = InputBox(“Enter the exact name of the element you would like to add as a button.”, “Adding Element Button”, “text”)

    Set newbutton = CommandBars(“Basic Elements”).Controls.Add(Type:=msoControlButton, ID:=2321, Parameter:=eName)

    newbutton.Caption = eName

    nReply = InputBox(“Would you like to add another element button? (y or n)?”, “Add Another Button?”, “n”)

    ‘Add another button loop

    Do Until nReply = “n”

    eName = InputBox(“Enter the exact name of the element you would like to add as a button.”, “Adding Element Button”, “text”)

    Set newbutton = CommandBars(“Basic Elements”).Controls.Add(Type:=msoControlButton, ID:=2321, Parameter:=eName)

    newbutton.Caption = eName

    nReply = InputBox(“Would you like to add another element button? (y or n)?”, “Add Another Button?”, “n”)

    Loop

    End Sub

    Viewing 0 reply threads
    Author
    Replies
    • #1047831

      > Can this be fixed in Word 2007?
      Well Jerry, since noone else appears ready to jump in ….

          Dim cb As CommandBar
          For Each cb In CommandBars
              If cb.Visible Then
                  cb.Protection = (cb.Protection And &H3)
              Else
              End If
          Next cb

      The snippet above functioned correctly in my Beta 2 back in July2006.
      This morning I d/l the Trial version. (“Trial” refers to what happens to me, not the status of the 2007)

      The code snippet refuses to work. It fails, and to make matters worse, the Help files in VBA look completely different from any earlier version.

      This posting is a heads-up on the potential for similar problems in Word2007 that were not apparent in the 2006 beta versions.

      • #1047941

        Thanks. I noticed that this problem no longer occured after I upgraded to B2TR.

        Jerry

        • #1048026

          > Thanks. I noticed that this problem no longer occured after I upgraded to B2TR.
          Does this mean that your problem has gone away and mine has just arrived?
          I believe that our problems are different, but are related to the same internal mechanism, that is “Command Bar” object.

    Viewing 0 reply threads
    Reply To: Macro Problem in Word 2007 (VBA / Office 2007)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: