Delete AppCustom MenuSet

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
 
J

John

Well I've managed to work out what I was doing wrong, so for anyone who's
interested..........

As I had a clone of the Application.CustomMenus, I was adding my menu to the
MenuSet for the whole of that drawing context. This meant that when I
removed it with the code below I removed the whole MenuSet (ie all of the
menus) for the drawing context (visUIObjSetDrawing).

The correct method therefore is to remove just my menu once I had a
reference to the correct MenuSet (using the caption identifier).

So remove code now looks like the amended code below.

Its worth mentioning, for anyone not familiar with it, that Graham Wideman's
book (http://diagramantics.com/) has helped a lot with trying to get my head
round the UIObject model amongst other things, including his UIObject
Browser tool that comes with the book (which helped me in spotting that I'd
deleted the entire Drawing context menus!)

Best regards

John


Sub RemoveUIItems()
'-------------------------------------------
Dim AUIObject As Visio.UIObject
Dim x As Integer
Dim i 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
For i = AUIObject.MenuSets(x).Menus.Count - 1 To 0 Step -1
If AUIObject.MenuSets(x).Menus(i).Caption = "MyMenu"
Then
AUIObject.MenuSets(x).Menus(i).Delete
End If
Next i
End If
Next x
' Now put it in place
Application.SetCustomMenus AUIObject
AUIObject.UpdateUI
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top