Consulting

Results 1 to 5 of 5

Thread: Customize Shortcut Menus for Word

  1. #1
    VBAX Regular
    Joined
    Mar 2022
    Posts
    8
    Location

    Customize Shortcut Menus for Word

    I customize the right-click menu like this
    Option Explicit
    Dim oPopUp As CommandBarPopup
    Dim oCtr As CommandBarControl
    Sub BuildControls()
    Dim oBtn As CommandBarButton
      'Make changes to the Add-In template
      CustomizationContext = ThisDocument.AttachedTemplate
      'Prevent double customization
      Set oPopup = CommandBars.FindControl(Tag:="custPopup")
      If Not oPopup Is Nothing Then GoTo Add_Individual
      'Add PopUp menu control to the top of the "Text" short-cut menu
      Set oPopUp = CommandBars("Text").Controls.Add(msoControlPopup, , , 1)
      With oPopUp
       .Caption = "My Very Own Menu"
       .Tag = "custPopup"
       .BeginGroup = True
      End With
      'Add controls to the PopUp menu
      Set oBtn = oPopUp.Controls.Add(msoControlButton)
      With oBtn
        .Caption = "My Number 1 Macro"
        .FaceId = 71
        .Style = msoButtonIconAndCaption
        'Identify the module and procedure to run
        .OnAction = "MySCMacros.RunMyFavMacro"
      End With
      Set oBtn = Nothing
      'Add a Builtin command using ID 1589 (Co&mments)
      Set oBtn = oPopUp.Controls.Add(msoControlButton, 1589)
      Set oBtn = Nothing
      'Add the third button
      Set oBtn = oPopUp.Controls.Add(msoControlButton)
      With oBtn
        .Caption = "AutoText Complete"
        .FaceId = 940
        .Style = msoButtonIconAndCaption
        .OnAction = "MySCMacros.MyInsertAutoText"
      End With
      Set oBtn = Nothing
    Add_Individual:
      'Or add individual commands directly to menu
      Set oBtn = CommandBars.FindControl(Tag:="custCmdBtn")
      If Not oBtn Is Nothing Then Exit Sub
      'Add control using built-in ID 758 (Boo&kmarks...)
      Set oBtn = Application.CommandBars("Text").Controls.Add(msoControlButton, 758, , 2)
      oBtn.Tag = "custCmdBtn"
      If MsgBox("This action caused a change to your Add-In template." _
         & vbCr + vbCr & "Recommend you save those changes now.", vbInformation + vbOKCancel, _
         "Save Changes") = vbOK Then
        ThisDocument.Save
      End If
      Set oPopUp = Nothing
      Set oBtn = Nothing
    lbl_Exit:
      Exit Sub
    End Sub

    When highlighting and selecting text, the re-added right click menu doesn't show up. Help me!
    Last edited by Aussiebear; 03-11-2022 at 12:43 PM. Reason: Added code tags to supplied code

  2. #2
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    123
    Location
    See Customize Text Shortcut Menu by Greg Maxey. If that is where you got your code, attribution would be a good thing.
    As noted on that page, you can also use custom XML to modify the context menus, somewhat more easily.

    Highlighting and selecting are different things.
    When you select text you are still going to get the Text Context Menu.

    There are a bunch of different context menus. I use the Add-In from this site to make sure of which one is being called. It gives the name at the bottom of the menu when it is called. https://www.add-in-express.com/creat...xt-menu-addin/

    Does the menu show up otherwise?

  3. #3
    VBAX Regular
    Joined
    Mar 2022
    Posts
    8
    Location
    Thanks you, but I mean when I select the object and then right click it won't show
    2022-03-12_141134.jpg

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,057
    Location
    A very good piece of code by Greg Maxey, and it seems that lamnbj doesn't care enough to acknowledge this point.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    123
    Location
    Did you try using the Add-In linked to check and make sure which contextual menu is being displayed? It looks like you are selecting an equation, which could be giving you a different menu.

    Again, if you started with code from someone else, that should be identified.

Posting Permissions

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