How to add into menu (msoControlPopup) the separator?

A

avkokin

Hello.
I have own menu as msoControlPopup with list some values (e.g.
bookmarks). Above this list I want to add other the item menu (e.g.
"Remove all bookmarks"). And I want to separate it from the list of
bookmarks. The list of bookmarks is lower than menu item "Remove all
bookmarks". I can to add the separator for menu item "Remove all
bookmarks". But it not showed.
If I add the separator for list of bookmarks then I get many
separators between each menu item.
Question: how can I add the separator for my top menu item?
Thank you very much. Below - code:

Set cbbRmv = cb.Controls.Add(msoControlPopup)
With cbbRmv
.Caption = "Remove bookmarks"

Set cbbAllDelBM = cbbRmv.Controls.Add(msoControlButton)
If ActiveDocument.Bookmarks.Count = 0 Then
cbbAllDelBM.Enabled = False
End If

With cbbAllDelBM
' .BeginGroup = True ' HERE NOT SHOWED !!!
.Caption = "Remove all bookmarks"
.OnAction = "delAllBM"
.FaceId = 1985
End With

'remove particular bookmarks
If ActiveDocument.Bookmarks.Count > 0 Then
For Each bm In ActiveDocument.Bookmarks
Set cbbDelBM = cbbRmv.Controls.Add(msoControlButton)
With cbbDelBM
.Caption = bm.Name
.Style = msoButtonCaption
.OnAction = "delBM"
.BeginGroup = True ' IT SHOW SEPARATOR BETWEEN
BOOKMARK !!!
End With
Next bm
End If
End With
 
J

Jonathan West

avkokin said:
Hello.
I have own menu as msoControlPopup with list some values (e.g.
bookmarks). Above this list I want to add other the item menu (e.g.
"Remove all bookmarks"). And I want to separate it from the list of
bookmarks. The list of bookmarks is lower than menu item "Remove all
bookmarks". I can to add the separator for menu item "Remove all
bookmarks". But it not showed.
If I add the separator for list of bookmarks then I get many
separators between each menu item.
Question: how can I add the separator for my top menu item?

To add a separator between the first and second items, set the BeginGroup
property of the second item to True.
 
A

avkokin

Hello Jonathan. Thank's for answer. But if I will add separatot for
second item then it will show between each items (bookmarks).
 
J

Jonathan West

avkokin said:
Hello Jonathan. Thank's for answer. But if I will add separatot for
second item then it will show between each items (bookmarks).

Somewhere towards the end of your macro, add this line

cbbRmv.Controls(2).BeginGroup = True

That should do the trick.
 
A

avkokin

Hello Jonathan.
There is one trick:

First = True

If ActiveDocument.Bookmarks.Count > 0 Then
For Each bm In ActiveDocument.Bookmarks
Set cbbDelBM = cbbRmv.Controls.Add(msoControlButton)
With cbbDelBM
.Caption = bm.Name
.Style = msoButtonCaption
.OnAction = "delBM"
'HERE!!!
If First Then
.BeginGroup = True
First = False
End If

End With
Next bm
 
J

Jonathan West

Yes, that works as well. Glad you've found something that achieves what you
want. One small comment. I like to ensure that all my variable names have a
prefix indicating the data type (in this case I would use bFirst indicating
a Boolean). This serves two purposes:

1. A quick reference to ensure that I don't make an inappropriate assignment
to the variable

2. To avoid possible confusion between variable names and properties in the
object model. There are several objects that have a First property (e.g. the
Paragraphs collection) and if you are using a With-End With structure, it
can be all too easy for there to be confusion between "First" and ".First".
Prefixing the variable name reduces the risk of this.
 

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