PDA

Click to See Complete Forum and Search --> : Adding to MSWord Right Click Menu


longwolf
Jan 11th, 2006, 02:37 PM
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:

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.


Public WithEvents appWord As Word.Application

Private Sub appWord_WindowBeforeRightClick _
(ByVal Sel As Selection, _
Cancel As Boolean)

Set myBar = CommandBars _
.Add(Name:="Custom", Position:=msoBarPopup, Temporary:=True)
With myBar
.Controls.Add Type:=msoControlButton, ID:=3
.Controls.Add Type:=msoControlComboBox
End With
myBar.ShowPopup

End Sub

RobDog888
Jan 13th, 2006, 01:42 PM
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?

longwolf
Jan 13th, 2006, 05:12 PM
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:

Dim X As New EventClassModule

Sub Register_Event_Handler()
Set X.appWord = Word.Application
End Sub

RobDog888
Jan 13th, 2006, 10:37 PM
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.


Dim oCB1 As Office.CommandBarButton

With myBar
Set oCB1 = .Controls.Add Type:=msoControlButton, ID:=3
oCB1.Caption = "My Menu Caption1"
oCB1. ...
oCB1. ...
oCB1. ...
End With