im having huge problems with a popup menu.
Everytime i run the macro it creates a new shortcutmenu item however if i
run the mcro few times i have the same menu item added everytime. I was
trying to code it so that if it already existed it would delete it and create
a new one using code like this :
Set clarpop = ShortCutMenu.Controls.Add(Type:=msoControlPopup)
For Each clarpop In ShortCutMenu.Controls
clarpop.Delete
Next clarpop
With clarpop
.Tag = "Litriu"
.Caption = "&Litriú"
.OnAction = "MenuAction"
End With
However that was giving me errors
Then i tried an if statement saying if there were less than 11 controls on
the shortcutmenu to add a new one otherwise dont - that didnt show any menu
item.
deleting menu item seems to always throw errors.
Any word of advice??
sarah was telling us:
sarah nous racontait que :
> im having huge problems with a popup menu.
> Everytime i run the macro it creates a new shortcutmenu item however
[quoted text clipped - 7 lines]
> clarpop.Delete
> Next clarpop
Here, you add a menu, and then right away try to delete it.... ?
Also, you are trying to delete a control by defining a popup menu (You
define clarpop a popup menu, but then try to use that variable to cycle
through controls.
Are you trying to add a menu or a control? With your code, you are adding a
menu that will never be accessible because as soon as you put the focus on
it, the MenuAction macro is launched.
> With clarpop
> .Tag = "Litriu"
[quoted text clipped - 8 lines]
>
> deleting menu item seems to always throw errors.
Try this instead:
'_______________________________________
Sub Test()
Dim MyCtrl As CommandBarControl
Dim ShortCutMenu As CommandBar
Set ShortCutMenu = CommandBars("Text")
For Each MyCtrl In ShortCutMenu.Controls
If MyCtrl.Tag = "Litriu" Then
MyCtrl.Delete
Exit For
End If
Next
Set MyCtrl = ShortCutMenu.Controls.Add(Type:=msoControlButton)
With MyCtrl
.Tag = "Litriu"
.Caption = "&Litri?"
.OnAction = "MenuAction"
End With
End Sub
'_______________________________________
'_______________________________________
Sub MenuAction()
MsgBox """Litri?"" was clicked on!", vbInformation, "Success!"
End Sub
'_______________________________________
Finally, are you sure you want to add this control to Normal.dot?
If not, look up the
CustomizationContext
property in the VBA on-line help.

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org