Supercharge your PowerPoint productivity with

Supercharge your PPT Productivity with PPTools - Click here to learn more.

Tell me about PPTools

Add a popup toolbar


PPTools
Shape Styles brings the power of styles to PowerPoint. Apply complex formatting with a single click
Merge Excel, CSV or tab-delimited data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more
FixLinks prevents broken links when you distribute PowerPoint presentations
Optimizer saves disk space and bandwidth, shrinks your PowerPoint presentations to the right size for email, screenshow or printing
PPT2HTML gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements
Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF
Image Export converts PowerPoint slides to JPG, PNG, GIF, WMF and more

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


Page copy protected against web site content infringement by Copyscape Contents © 1995-2008 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.

Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese



Supercharge your PPT Productivity with PPTools


content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Add a popup toolbar
http://www.pptfaq.com/FAQ00768.htm
Last update 20 November, 2006