Consulting

Results 1 to 3 of 3

Thread: Solved: individual Contextmenu in Powerpoint?

  1. #1

    Question Solved: individual Contextmenu in Powerpoint?

    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


  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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 :-)

  3. #3
    Thx!

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

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •