Custom context-menu item

U

Uzi

Hi,

Right clicking the mouse pops-up a context menu depending on the
selected object.
How do I add a custom menu item to the context menu which pops-up when
right-clicking on a shape in PowerPoint?

Thanks a lot,

Uzi
 
S

Shyam Pillai

Do you want to do this programmatically or otherwise? Also, which is the
PowerPoint version you are using?
 
U

Uzi

Hi Shyam,
I want to do it programmatically. My PowerPoint version is 2002.
I need to access, somehow, the correct shortcut menu. the one that pops
up when selecting a shape on a slide and right clicking
 
S

Shyam Pillai

Uzi,
The routine below will allow you to add menu items to a specific shortcut
menu. You have to provide the name for it.

Usage:
Call AddItemToShortcutMenu("Shapes","RunThis","This is a new item...")


' ==============================================================
' Parameter description
' ShortcutMenuName: Name of the shortcut menu within which the menu item is
to be created
' OnActionMacro: Name of macro to be executed when user selects the menu
item
' Caption: Caption for the menu item.

' ==============================================================
Sub AddItemToShortcutMenu(ShortcutMenuName As String, _
OnActionMacro As String, _
Caption As String)
Dim cbMenuItem As CommandBarButton
Dim cbContainer As CommandBarPopup
On Error Resume Next
Set cbContainer = Application.CommandBars("Shortcut Menus") _
.Controls("Draw").Controls(sName)
If cbContainer Is Nothing Then
MsgBox "Could not find shortcut menu with that name.", vbExclamation
Exit Sub
End If
With cbContainer.Controls
Set cbMenuItem = .Add(Type:=msoControlButton)
With cbMenuItem
.OnAction = OnActionMacro
.Caption = Caption
End With
End With
End Sub
' ==============================================================

--
Regards,
Shyam Pillai

Toolbox: http://skp.mvps.org/toolbox

There are several shortcut menus which are categorized in the PowerPoint
object model
 
U

Uzi

Hi Shyam,
Thanks a lot!
You need to send the shortcut menu name to the function you wrote. I
can see most of the shoutcut menu names and their content from the
PowerPoint menu Tools -> Customize and selecting the shortcut menus.
But there is at least one menu which is not there and I don't know how
to get it's name: I mean the shortcut menu which pops up when right
clicking on a diagram, for example an organization-chart diagram node.
How do I know this shortcut menu's name?
Thanks again,
Uzi
 
S

Shyam Pillai

Those you need to add to the command bar directly.

CommandBars("Organization Chart Popup") is the commandbar you are looking
for.
 
U

Uzi

Thanks, Shyam

After planting my custom controls in the desired menu, I need to do
some checking before the menu pops up to determine if the control
should be enabled or disabled. Is there any way for me to handle the
event of the shortcut menu poping up? I don't see a 'popup' event which
is available in windows forms in .net.

Uzi
 
S

Shyam Pillai

When I wish to do this with an custom item contained within a shortcut menu,
I usually place all the custom menu items within a popup control. This way,
when the user clicks on the popup to cascade down the menu items, I can run
a macro and set the states of the child items before it shows up in the UI.

Alternately, never versions of Office does offer commandbar update events if
you wish to hook into them.
 

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