Remove a Control from Context Menu MSW 2007

R

rick

I used this code to add "Underline" to the context menu in MS Word 2007:

CommandBars("Text").Controls.Add Type:=msoControlButton, ID:=115,
Before:=2

It worked a treat. Only problem: I ran it about 7 times before I realised
it was adding the control to my Normal template and not the document I had
opened.

Now I have 6 additional instances of the control whenever I open a new
document, and I'd like to get rid of them. There doesn't seem to be an
equivalent "Delete" or "Remove" function, and don't just want to hide them
which seems to be what Help suggests.

Thanks in advance.

Rick.
 
R

rick

Tony Jollans said:
One way ...

CommandBars("Text").FindControl(ID:=115).Delete

--
Enjoy,
Tony

www.WordArticles.com

Thanks!

I also found another way:

CommandBars("Text").Controls(1).Delete

"1" being the Index Number of the control I want to delete.

What is annoying is that it takes so long to find these simple things using
VBA's Object Browser or Help. You'd think "Add" and "Delete" would be
together under CommandBarControl or CommandBarControls, or they would be
linked by a hyperlink, but they're completely separate!

My original problem came about because each context menu is different (ie
"Text", "Table Text" and "List"), and I was looking for the new control in a
List context menu, and not ordinary text; so I kept running the code :-(

I have a slightly new problem: I want to add Separators. They appear
spontaneously in some menus, and in other menus they don't. Can't seem to
find an ID no. for them.

This was a lot easier in MS Word 2003!!

Thanks in advance.

Rick
 
T

Tony Jollans

You need to set the BeginGroup property of the control to True to get a
separator before it, so for your underline you could do ...

CommandBars("Text").Controls.Add(Type:=msoControlButton, _
ID:=115, Before:=2).BeginGroup = True
 
R

rick

Tony Jollans said:
You need to set the BeginGroup property of the control to True to get a
separator before it, so for your underline you could do ...

CommandBars("Text").Controls.Add(Type:=msoControlButton, _
ID:=115, Before:=2).BeginGroup = True

--
Enjoy,
Tony

www.WordArticles.com

Thank again for the clue!

I tried (and it worked):

CommandBars("Text").Controls(2).BeginGroup = True

"2" since I wanted the separator before the 2nd control.

It also worked for CommandBars("Lists") but for some reason won't work for
CommandBars("Table Text"). Any ideas?

Will also take the opportunity to whine how the online help makes it so
difficult to find help on creating separators.

TIA.

Rick
 
T

Tony Jollans

Sorry, no ideas! It works for me.

I'll happily whine with you, but I doubt it'll make any difference :-(
 

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