Add a popup toolbar
This sample code shows you how to create and display a popup toolbar that uses both built-in PowerPoint methods (the Save button on the toolbar) and calls your own routines (the Do Stuff) button.
Run CreateThePopup to create the popup menu, then call or manually run DisplayMyPopup to display and use the popup menu.
Sub CreateThePopup() Dim oCmdBar As CommandBar Dim oCtrl As CommandBarControl ' delete the popup if it already exists For Each oCmdBar In Application.CommandBars If UCase(oCmdBar.Name) = UCase("myPopup") Then oCmdBar.Delete Debug.Print "Found/Deleted existing popup" Else Debug.Print oCmdBar.Name End If Next ' commandbar Set oCmdBar = Application.CommandBars.Add(Name:="myPopup", Position:=msoBarPopup) With oCmdBar ' Add a SAVE button Set oCtrl = .Controls.Add(Type:=msoControlButton, Id:=3) 'add a Do Stuff button that calls your doStuff subroutine (see below) Set oCtrl = .Controls.Add(Type:=msoControlButton) With oCtrl .FaceId = 10 .Caption = "Do stuff" .OnAction = "doStuff" End With End With End Sub Sub DisplayMyPopup() ' Call this sub to display the popup Application.CommandBars("myPopUp").ShowPopup End Sub Sub doStuff() MsgBox "I did stuff" End Sub
OK, SuperEgo, where did ID come from?
How did we know what ID to use in this line above?
Set oCtrl = .Controls.Add(Type:=msoControlButton, Id:=3)
This little bit of code will list all of the available IDs for you:
Sub ListIDs() Dim oCtl as CommandBarControl Dim oCmdBar as CommandBar Dim sFileName as String Dim iFileNum as Integer ' Change this if you'd rather put the file elsewhere sFileName = "C:\temp\PowerPointIDs.TXT" iFileNum = FreeFile() Open sFileName For Output As iFileNum For Each oCmdBar In Application.CommandBars Print #iFileNum, oCmdBar.Name For Each oCtl In oCmdBar.Controls Print #iFileNum, oCtl.Id & vbTab & oCtl.Caption Next Next Close iFileNum End Sub