Results 1 to 14 of 14
  1. #1
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing menus (2003 SP3)

    Is there any way of referring to a Menu item in VBA other than by a number (such as below)?
    CommandBars("Custom Popup 177922703").Controls(1).
    The index number is OK, once I know that I am actually referring to the correct Menu item. I can't find any way of ensuring that the number (177922703) really does refer to the Menu item I want to alter. A name would be much easier and safer.
    Regards,
    Peter

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Accessing menus (2003 SP3)

    I don't understand - "Custom Popup 177922703" is a name, not a number. The same command bar may be CommandBars(135) or something like that.

    Are you creating this in code? If so, you can change the name to anything you want (as long as it's unique).

  3. #3
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Accessing menus (2003 SP3)

    G'day Hans.
    The problem arises because Acrobat overwrites my custom Menu item at every re-boot and at many openings of Word. Not being familiar with Word VBA, I recorded a macro when I deleted the sub Menu items under the main Menu item and re-inserted my macros into that main Menu item. The recorded macro referred to the Main Menu item as shown below, but I am certain that that number does not in fact refer to my Menu item.
    This is how the recorded macro referred to the Menu item:
    CommandBars("Custom Popup 177922703").Controls(1)
    I tried this: CommandBars("PK Sig").Controls(1); where "PK Sig” is the name of my main Menu item, but it doesn’t work.
    How can I use a name instead of that number?
    Regards,
    Peter

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Accessing menus (2003 SP3)

    Does this work?

    CommandBars("Menu Bar").Controls("PK Sig").Controls(1)

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Accessing menus (2003 SP3)

    I tried
    ? CommandBars("Menu Bar").Controls("PK Sig").Controls.count
    in the immediate window and got an error 'Method or Data member not found'
    Regards,
    Peter

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Accessing menus (2003 SP3)

    Where does your "PK Sig" live? In the main menu bar, or ???

  7. #7
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Accessing menus (2003 SP3)

    I have added "PK Sig" to the main Menu bar. Under that I add various signatures I use as sub menu items. Acrobat removes all these sub menu items and sometimes installs it's own sub menu items that also appear in another Acrobat main Menu item. The main Menu item "PK Sig" is always there, but ususally ends up bare.
    Regards,
    Peter

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Accessing menus (2003 SP3)

    Does

    ? CommandBars("Menu Bar").Controls("PK Sig").Caption

    raise an error message? If you have set an underlined letter, you must place an & before that letter, e.g. for PK Sig you should use

    ? CommandBars("Menu Bar").Controls("PK &Sig").Caption

  9. #9
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Accessing menus (2003 SP3)

    It works. I'm a dill! The name of the Menu item is 'PK Sign' not 'PK Sig'. It works well when I use the correct name!!!
    Thanks again, again Hans
    Regards,
    Peter

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Accessing menus (2003 SP3)

    Phew!
    Attached Images Attached Images

  11. #11
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Accessing menus (2003 SP3)

    Love the DUH!
    I still have a problem. I have searched high and low but cannot find any hint of how to add items beneath the Menu item 'PK Sign'.
    I put on redord macro while I did it manually and that gave me the code below:
    CommandBars("Custom Popup 177262843").Controls.Add Type:=msoControlButton, Before:=4
    This seems a bit weird and obviously does nothing. So how do I add macros under the Menu item 'PK Sign' using VBA?
    The macros I want to add are called
    SigPeter; SigPKLE; SigPKLE_TEXT; SigPK_WithInfo; & SigDad. All of them in Normal.dot
    Also, how would I then change the name of those sub menu items in VBA code?
    Regards,
    Peter

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Accessing menus (2003 SP3)

    You'd use something like this:

    Dim cbr As CommandBar
    Dim cbp As CommandBarPopup
    Dim cbb As CommandBarButton

    Set cbr = CommandBars("Menu Bar")
    Set cbp = cbr.Controls("PK Sign")

    Set cbb = cbp.Controls.Add(Type:=msoControlButton)
    With cbb
    .Caption = "Peter's Signature"
    .OnAction = "SigPeter"
    .Style = msoButtonCaption
    End With

    Set cbb = cbp.Controls.Add(Type:=msoControlButton)
    With cbb
    .Caption = "Another Signature"
    .OnAction = "SigPKLE"
    .Style = msoButtonCaption
    End With

    ...

  13. #13
    5 Star Lounger
    Join Date
    May 2001
    Location
    Patterson Lakes, Melbourne, Victoria, Australia
    Posts
    637
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Accessing menus (2003 SP3)

    You beauty Hans. It works.
    Oh what a joy. I have been suffering from Adobe stuffing up my menu for over a year. Now I can stuff up Adobe's stuff up.
    I couldn't find any hint anywhere (except here) that a menu item is in fact a CommandBarPopup and that a menu item sub item is a CommandbarButton. The last one seems very obtuse.
    Thanks again Hans, again.
    Regards,
    Peter

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Accessing menus (2003 SP3)

    Menu items are identical to toolbar buttons in MS Office, and CommandBarButton is the VBA name for both.

Posting Permissions

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