Results 1 to 4 of 4

Thread: Adding to MSWord Right Click Menu

  1. #1

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Adding to MSWord Right Click Menu

    Hi,
    I pretty good with VB6, but haven't worked with VBA.

    Here's what I want to do,
    I have a list of words that have matching replacement words.

    If the user selects and right clicks a word in his WOrd Doc, I want to search my list.
    If the selected word is in the list I want to temp add a new option to the right click menu, the option would have a sub menu of the matching words from the list.

    Example:
    Code:
        Cut
        Copy
        Paste
        --------------
        Optional Words
            Repalcement1
            Repalcement2
            Repalcement3
    I've been going through the help files and cobbled this together, but it's not quite it.

    I supose I could add the replacment words to the combo, but I wouldn't know how to add them or what sub to add in order to react to a combobox click.

    VB Code:
    1. Public WithEvents appWord As Word.Application
    2.  
    3. Private Sub appWord_WindowBeforeRightClick _
    4.         (ByVal Sel As Selection, _
    5.         Cancel As Boolean)
    6.    
    7.     Set myBar = CommandBars _
    8.         .Add(Name:="Custom", Position:=msoBarPopup, Temporary:=True)
    9.     With myBar
    10.         .Controls.Add Type:=msoControlButton, ID:=3
    11.         .Controls.Add Type:=msoControlComboBox
    12.     End With
    13.     myBar.ShowPopup
    14.  
    15. End Sub

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Adding to MSWord Right Click Menu

    Looks like your on the right track but your loosing me on what the issue really is and whats going on with this combobox? I thought you needed a popup menu?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Adding to MSWord Right Click Menu

    I really wasn't after a combobox, it's just the only code I was able to find in the help files that came close to what I'm after.

    It would be better if I could just add a new menu item ("Optional Words") and then add sub items.

    But I haven't got a clue where to start.

    Alternately I might be able to use the combobox, but I would need to know how to add items to it, and how to react to a click event for the box.

    p.s.
    I forgot to mention that the code from the 1st post is in a class module named "EventClassModule"

    and there is a normal module named Module1 with the following code:
    VB Code:
    1. Dim X As New EventClassModule
    2.  
    3. Sub Register_Event_Handler()
    4.     Set X.appWord = Word.Application
    5. End Sub

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Adding to MSWord Right Click Menu

    Ok, you should use a different name for your custom menu item - Name:="Custom". Should be something that may not conflict with any reserved words amd related to its purpose.


    VB Code:
    1. Dim oCB1 As Office.CommandBarButton
    2.  
    3. With myBar
    4.     Set oCB1 = .Controls.Add Type:=msoControlButton, ID:=3
    5.     oCB1.Caption = "My Menu Caption1"
    6.     oCB1. ...
    7.     oCB1. ...
    8.     oCB1. ...
    9. End With
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width