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
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
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 window[VBA]Sub 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 Sub[/VBA]Once 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 this[VBA]Option 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[/VBA]
K :-)
Thx!
I found exactly, what I was looking for: "Frames"
... CommandBars("Frames").Controls.Add ...