PDA

View Full Version : Solved: individual Contextmenu in Powerpoint?



Mark2005
07-04-2006, 07:31 AM
How can I do an individual Contextmenu in Powerpoint?
I want to do it in VBA - in Excel was it done pretty easily, but in Powerpoint it seems to be more tricky.

Any Idea or help would be very nice


thx

Killian
07-05-2006, 03:36 AM
It's the same principle - identify the command bar by name or ID and add a control. It's a bit more confusing because there are a lot of context menus to choose from in PowerPoint...

The following code will show each of the "popup" command bars and thier IDs in the Immediate windowSub OutputCommandBarNames()

Dim cb As CommandBar

For Each cb In Application.CommandBars
If cb.Type = msoBarTypePopup Then
Debug.Print cb.Name
End If
Next cb

End SubOnce you've identified which one's you want to modify, you can add/delete a control in the usual fashion.

So, a module to manage a custom control on the "Pictures" context menu (when right-cilcking a picture) could work like thisOption Explicit

Dim cb As CommandBar
Dim ctrl As CommandBarControl
Dim ctrlNew As CommandBarControl

Sub AddContextMenuItem()
'call when this project loads
For Each cb In Application.CommandBars
If cb.Name = "Pictures Context Menu" Then
Set ctrlNew = cb.Controls.Add
ctrlNew.Caption = "TEST"
ctrlNew.OnAction = "TESTroutine"
Set ctrlNew = Nothing
End If
Next cb

End Sub

Sub DeleteContextMenuItem()
'call when this project unloads
For Each cb In Application.CommandBars
If cb.Name = "Pictures Context Menu" Then
For Each ctrl In cb.Controls
If ctrl.Caption = "TEST" Then
ctrl.Delete
End If
Next ctrl
End If
Next cb

End Sub

Sub TESTroutine()
MsgBox "Menu item '" & Application.CommandBars.ActionControl.Caption & "' was clicked"
End Sub

Mark2005
07-06-2006, 01:40 AM
Thx!

I found exactly, what I was looking for: "Frames"

... CommandBars("Frames").Controls.Add ...