Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Apr 2002
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro Problem in Word 2007 (VBA / Office 2007)

    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

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problem in Word 2007 (VBA / Office 2007)

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

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


    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.
    Attached Images Attached Images
    • File Type: jpg 1.JPG (21.5 KB, 12 views)

  3. #3
    Lounger
    Join Date
    Apr 2004
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problem in Word 2007 (VBA / Office 2007)

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

    Jerry

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro Problem in Word 2007 (VBA / Office 2007)

    > 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •