J
John
Hi there,
I'm having trouble with trying to delete a particular MenuSet. My code
(which is in a stencil) successfully adds a new menu and a number of items,
using the Application.SetCustomMenus method.
When adding I set the MenuSet.Caption as below so that I can identfy it
later to remove it:
Set AMenuSet = AUIObject.MenuSets.ItemAtID(visUIObjSetDrawing)
AMenuSet.Caption = "MyAppCustomMenuSet"
The RemoveUIItems code (below) appears to find the correct MenuSet using the
caption (this is verified by the Debug statement and it executes they
..Delete line too), but when it gets to the .SetCustomMenus line the UI menu
items are disabled but NOT removed. (NB - They do dissappear when the
respective document is closed, but I have to relaunch Visio in order to
rerun the add menus code again.
Can anyone see my presumably obvious mistake?
Best regards
John
(Visio 2003)
Sub RemoveUIItems()
'-------------------------------------------
Dim AUIObject As Visio.UIObject
Dim x As Integer
Set AUIObject = Application.CustomMenus.Clone
If Not AUIObject Is Nothing Then
For x = AUIObject.MenuSets.Count - 1 To 0 Step -1
Debug.Print x, AUIObject.MenuSets(x).Caption
If AUIObject.MenuSets(x).Caption = "MyAppCustomMenuSet" Then
AUIObject.MenuSets(x).Delete
End If
Next x
' Now put it in place
Application.SetCustomMenus AUIObject
AUIObject.UpdateUI
End If
End Sub
I'm having trouble with trying to delete a particular MenuSet. My code
(which is in a stencil) successfully adds a new menu and a number of items,
using the Application.SetCustomMenus method.
When adding I set the MenuSet.Caption as below so that I can identfy it
later to remove it:
Set AMenuSet = AUIObject.MenuSets.ItemAtID(visUIObjSetDrawing)
AMenuSet.Caption = "MyAppCustomMenuSet"
The RemoveUIItems code (below) appears to find the correct MenuSet using the
caption (this is verified by the Debug statement and it executes they
..Delete line too), but when it gets to the .SetCustomMenus line the UI menu
items are disabled but NOT removed. (NB - They do dissappear when the
respective document is closed, but I have to relaunch Visio in order to
rerun the add menus code again.
Can anyone see my presumably obvious mistake?
Best regards
John
(Visio 2003)
Sub RemoveUIItems()
'-------------------------------------------
Dim AUIObject As Visio.UIObject
Dim x As Integer
Set AUIObject = Application.CustomMenus.Clone
If Not AUIObject Is Nothing Then
For x = AUIObject.MenuSets.Count - 1 To 0 Step -1
Debug.Print x, AUIObject.MenuSets(x).Caption
If AUIObject.MenuSets(x).Caption = "MyAppCustomMenuSet" Then
AUIObject.MenuSets(x).Delete
End If
Next x
' Now put it in place
Application.SetCustomMenus AUIObject
AUIObject.UpdateUI
End If
End Sub