Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning current context menu in Word 2003

Status
Not open for further replies.

Jarosite99

Technical User
Mar 19, 2009
4
AU
Hi. This must be possible but I can't do it.

What I want to do is return the name of the current context menu as though I had right-clicked at the selection point. I know how to add menu items to builtin menus like this:

Set myControl = CommandBars("Text").Controls.Add(Type:=msoControlComboBox, Before:=1)
With myControl
.AddItem Text:="First Item", Index:=1
End With
End Sub

but that is not what I want to do as I am not adding a menu item.

I merely want to return the name of the context menu relevant to the selection point because of the rich information it provides about the place in the document (much better than range, story etc IMHO).

(So I want to be able to return the information represented by the builtin menus that are listed if you right-click the menu bar and click Customize, Shortcut Menus. I know that some or all of this info is available via various other methods but it would be simpler if I could get it via the shortcut menus.)

I have tried things like msgbox(CommandBars.Name) until the cows came home. No luck.

Thanks in anticipation.
 
Actually, I didn't express that very well.

What I want to do is return the name of the current context menu that the user has clicked or could click.
 
My apologies. I wasn't aware of the convention and didn't mean to cause offence. I simply perceived that some people did not have the answer I was seeking and thought that others might.

Consider the matter closed.
 
I simply perceived that some people did not have the answer I was seeking and thought that others might."

That indeed may be true, but you should mention it when you cross-post. Why? See here.

In any case, you are correct, it is closed, as Tony mentions...it can not be done. And as I have mentioned elsewhere, that is because:

"return the name of the current context menu"

it does not have a name.

Gerry
 
Well I learned something. I did not know it was considered cross-posting when the posts are at entirely different domains.

--Lilliabeth
 
Gerry,

All the context menus do have names. Go to Tools > Customize > Toolbars tab and check "Shortcut Menus" and you will get a toolbar from which they can all be customized, and which shows the names - it doesn't tell you which will be used in any particular situation, that you have to figure out by yourself, but they are all named.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Named? You know I am very wary of disagreeing with you Tony...but I think - at least until I understand something which I very well may not fully - that I am going to have to disagree.

Yes, there is text for items off the Shortcut Menus, but I do not think these are names, as far as I understand the word to mean.

For example:

Pick one (almost any one...) and you can see Cut. Right click that and you see - ahem - another context menu. "Name" is Cu&t.

But that is not its "name". It is the text displayed. In a sense its "name" is Sub EditCut(). And the only way I know of to find that out is to loop through the items items and reading its .OnAction value.

Let me ask about another example.

From the Shortcut Menus toolbar, under Text, you can see:

Display Fields

and

Fields

The Display Fields context menu items are:

Cut
Copy
Paste
Edit Fields
Toggle Field Codes
Font
Paragraphs
Bullets and Numbering

The Fields context menu items are:

Cut
Copy
Paste
Update Fields
Edit Fields
Toggle Field Codes
Font
Paragraphs
Bullets and Numbering

Are you trying to tell me that there is a distinct named object - even if not exposed to VBA - a context-sensitive menu object named "Display Fields", or "Fields", or "Greeting Line"? So that when you right-click Word internally calls that "Display Fields" menu...by name?

Hmmmm, on second thought, perhaps you are right. How else would the correct menu be displayed? Hmmmmm. Do you know this for a fact?

Hmmmm. OK, it uses a number of API, DisplayContextMenu for one. WM_CONTEXTMENU

There is also an interesting registry item: ContextMenuHandlers.

OK. I will buy that. They are named.

Gerry
 
They are command bars - "Display Fields", "Fields", "Greeting Line", etc., are their Names.

In VBA (the Immediate Window will do) run:

Code:
[blue]CommandBars("Display Fields").ShowPopup[/blue]

and the (basic) context menu will show. (not sure about Greeting Line off the top of my head - you might need Japanese enabled for that one).

Most context menus have Cut, Copy, and Paste on them, and some other general and relevant specific items, but many of the other items are dynamic, built when the menu is invoked.

You can use the Names to customize the menus in code, but not really for much else.

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Many thanks Tony.

I appreciate your expertise and the professional manner of your response.

Sorry for my slow response - been busy.

Regards, J.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top