First, it's not "the" right-click menu -- there are lots of them, depending
on the selection at the time. To see the list, right-click any existing
toolbar, select Customize, and check 'Shortcut menus' on the Toolbars tab.
The Shortcut menus toolbar, visible only when customizing, gives you access
to the shortcut menus in order to customize them manually.
Rather than adding and removing options each time, it might be easier to add
all the options when your code loads (perhaps when you initialize your class
module), then show/hide the ones you want.
You can retain persistent references to the options that you add --
set mnuAdd = CommandBars.....Add(...)
You can check if a menu contains a given options by examining its Controls
collection. When you add an option you can set its Tag property; you can
then use CommandBars.FindControl(Tag:=...) to retrieve it.
Note that menus are part of Office, not part of Word. They are defined in
the Office library. Menus and toolbars are the same thing. The difference is
only whether the options are shown as trext or as icons.
> Thank you very much!!! It works!!!
>
[quoted text clipped - 7 lines]
>
> Thanks again
sharon3874 - 30 Oct 2006 20:34 GMT
Thank you very much again!!!! I really appreciate your help!!!
It is very informative, but I still got problems.
(1). the menu items were displayed, but they showed up even I made the
visibility to false(or enabled to false).
(2). Every time I close and open the doc, menu items keep adding to the
end of the existing menu bar(which includes the menu items that added
last time). The menu item looks like this:
...
...
...
Add Additional Link
Edit Additional Link
Remove Additional Link
Add Additional Link
Edit Additional Link
Remove Additional Link
...
...
...
Actually, I just want them displayed once no matter how many times that
I close and open the doc. I tried to make "Temporary" to true when I
added the menu item, but it didn't seem to work.
Can you help to see my code?
Private Sub Class_Initialize()
Dim myMenuBar As CommandBar
Dim newMenu As CommandBarControl
Set myMenuBar = CommandBars("Hyperlink Context Menu")
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlButton, _
Temporary:=True)
newMenu.Caption = "Add Additional Link"
newMenu.Tag = "add"
newMenu.OnAction = "AddAdditionalLinks"
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlButton, _
Temporary:=True)
newMenu.Caption = "Edit Additional Link"
newMenu.Tag = "edit"
newMenu.OnAction = "AddAdditionalLinks"
Set newMenu = myMenuBar.Controls.Add(Type:=msoControlButton, _
Temporary:=True)
newMenu.Caption = "Remove Additional Link"
newMenu.Tag = "remove"
End Sub
Private Sub appWord_WindowBeforeRightClick(ByVal Sel As Selection,
Cancel As Boolean)
...
...
...
Dim rightClickMenuBar As CommandBar
Dim rightClickMenuItem As CommandBarControl
Set rightClickMenuBar = CommandBars("Hyperlink Context Menu")
If isExists = False Then
Set rightClickMenuItem =
rightClickMenuBar.FindControl(Tag:="edit")
rightClickMenuItem.Visible = False
Set rightClickMenuItem =
rightClickMenuBar.FindControl(Tag:="remove")
rightClickMenuItem.Visible = False
Else
Set rightClickMenuItem =
rightClickMenuBar.FindControl(Tag:="add")
rightClickMenuItem.Visible = False
End If
...
...
...
End Sub