Word right-click menu

M

Merlin

I am writing Word Addin and would like to know if it is possible to add some
menu items to the context sensitive Menu that pops up when you Right Click on
a selection in a Word Document.
Cheers
Merlin
 
P

Peter Huang [MSFT]

Hi Merlin,

I understand that you mean the Text menu as below.
Text
--------Cu&t
--------&Copy
--------&Paste
--------Delete Co&mment
--------Recon&vert
--------&Font...
--------&Paragraph...
--------Bullets and &Numbering...
--------Te&xt Direction...
--------&Symbol...
--------&Hyperlink...
--------&Who Is...
--------Loo&k Up...
--------&Define
--------S&ynonyms
--------Tr&anslate
--------&Select Text with Similar Formatting

So that we can use the code below to add another new button
Sub Test()
Dim cb As CommandBarButton
Set cb = Application.CommandBars("Text").Controls.Add
cb.Caption = "Testafasfasfasdf"
End Sub


Also you may run the code below to get a list of available Word's
commandbars/buttons.
Sub TestButtons()
Dim fso As New Scripting.FileSystemObject
Dim ts As Scripting.TextStream
Set ts = fso.CreateTextFile("C:\WordCommandBars.txt", True, True)
Dim cb As CommandBar
Dim cbc As CommandBarControl
For Each cb In CommandBars
ts.Write cb.Name & vbCrLf
For Each cbc In cb.Controls
ts.Write "--------" & cbc.Caption & vbCrLf
Next
Next
ts.Close
End Sub

It will generate a text file C:\WordCommandBars.txt.

Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Calin

Yes it is possible.
I already did that some years ago and it is easy. All the infomations you
need for that, you'll find'em in MSDN (since at least MSDN oct 2001).

Cheers, Calin
 
C

Cindy M.

Hi =?Utf-8?B?TWVybGlu?=,
I am writing Word Addin and would like to know if it is possible to add some
menu items to the context sensitive Menu that pops up when you Right Click on
a selection in a Word Document.
Yes, it's possible. The context menus are commandbars, just like the "real"
menus and the toolbars. The tricky part is determining exactly which
commandbar(s) you want to affect.

In Word: Tools/Customize/Toolbars. Activate the entry "Shortcut menus". You'll
get a toolbar with three buttons: Text, Table, Draw. These are the three main
categories of "selection". If you drop these down, you'll see the lists of
built-in pop menus for each type of selection context, such as Comments, Fields,
Text. You have to determine which of these are relevant to the type of selection
you have in mind, then add your control to each of them.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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