+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    06-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007
    Posts
    5

    Excel/PowerPoint 2007 Right Click Menues

    Hi guys,

    It's a pretty simple question with hopefully a simple answer:

    In Office 2003 it was pretty easy to add macros to the right-click menus in excel and PowerPoint. Does anyone know how to do this in the Office 2007 version. I've only found online explanation about how to add macros to the ribbon bar.

    Any help would be great.

    Thanks!

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Excel/PowerPoint 2007 Right Click Menues

    You do it in exactly the same way. That is via the CommandBar object.

    What you can not do is build menus on the ribbon. This appear on the Addins Tab.
    For stuff on the ribbon you need to create ribbon xml.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    06-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Excel/PowerPoint 2007 Right Click Menues

    Thanks for your help. But I took the code directly over from 2003 and it doesn't appear to be working. Is there something that needs to be named or called differently?

    Thanks!

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Excel/PowerPoint 2007 Right Click Menues

    can you post the code or workbook
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    06-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Excel/PowerPoint 2007 Right Click Menues

    Code:
    Sub AddRightClick()
    
    Dim customMenu
    Dim customMenu2 As CommandBarPopup
    
    Application.CommandBars("Shortcut Menus").Reset
    
    Set customMenu = Application.CommandBars("Shortcut Menus").Controls(3)  ' "Draw"
    For I = 1 To 12
    Set customMenu2 = customMenu.Controls(I) ' "Shapes" '2
    
    customMenu2.Controls(1).BeginGroup = True
    
    With customMenu2.Controls.Add(Temporary:=True, before:=1)
           .Caption = "More Information"
           .OnAction = "LoadInfo"
           .Style = msoButtonIconAndCaption
           .FaceId = 353
    End With
    
    With customMenu2.Controls.Add(Temporary:=True, before:=1)
           .Caption = "Change Event Time"
           .OnAction = "LoadForm"
           .Style = msoButtonIconAndCaption
           .FaceId = 126
    End With
    
    Next I
    
    End Sub
    Here is the code that's used in 03. I was wondering what the 2007 name is for the "shortcut menu" command bar. And also a list of the sub menus - for instance, control(3) was the draw menu in 03.

    Thanks

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Excel/PowerPoint 2007 Right Click Menues

    It would appear adding to contextual menus in PPT is now defunct.

    Excel though is more accomodating. This would for me, addin an item to the right click on worksheet.

    Try this in the immediate window of excel.
    Code:
    application.CommandBars("Cell").Controls.Add(msoControlButton).Tag="APTEST"
    application.CommandBars.FindControl(Tag:="APTEST").Caption="Hello"
    
    ' To remove it
    application.CommandBars.FindControl(Tag:="APTEST").Delete
    Cheers
    Andy
    www.andypope.info

  7. #7
    Registered User
    Join Date
    06-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Excel/PowerPoint 2007 Right Click Menues

    Thanks that seems to work in excel. So, would this not be possible in PowerPoint?

    What if its not a contextual menu, but I would like to just have that right click macro available (regardless of if its on all the time or not).

    You reference the commandbar("cell") is there nothing like that now for PowerPoint?

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Excel/PowerPoint 2007 Right Click Menues

    defunct = not possible

    Maybe this will make it clearer.

    Code:
    Sub AddContextMenu()
    
        Dim cbrTemp As CommandBarButton
        Dim strBefore As String
        Dim strAfter As String
        Dim strMenuName As String
        
        strMenuName = "Shortcut Menus"
        strMenuName = "Connector"
        
        strBefore = m_ListControls(Application.CommandBars(strMenuName))
        
        Set cbrTemp = Application.CommandBars(strMenuName).Controls.Add(msoControlButton)
        cbrTemp.Tag = "APTEST"
        cbrTemp.Caption = "Hello"
        cbrTemp.Visible = True
        cbrTemp.Enabled = True
        
        strAfter = m_ListControls(Application.CommandBars(strMenuName))
        
        MsgBox strBefore, , "Controls Before"
        MsgBox strAfter, , "Controls After"
        
    End Sub
    
    Sub ListCommands()
        Dim cbrTemp As CommandBar
        
        For Each cbrTemp In Application.CommandBars
            If cbrTemp.Type = msoBarTypePopup Then
                Debug.Print cbrTemp.Name
            End If
        Next
            
    End Sub
    
    
    Private Function m_ListControls(CBar As CommandBar) As String
        Dim cbcTemp As CommandBarControl
        Dim strTemp As String
        
        For Each cbcTemp In CBar.Controls
            strTemp = strTemp & cbcTemp.Caption & vbLf
        Next
        m_ListControls = strTemp
        
    End Function
    
    
    Sub RemoveContextMenu()
    
        Application.CommandBars.FindControl(Tag:="APTEST").Delete
        
    End Sub
    The AddContextMenu routine will add a new item to the named context menu.
    It will display all the controls before and after. You should see the new item added.

    If you then check the list against what actually appears you will see they don't quite match. It would appear the old commandbar items are there but the new contextual menus are actually displayed.

    So to restate. Not possible in ppt 2007.

    You can add controls to the ribbon in order to execute your macros.
    Cheers
    Andy
    www.andypope.info

  9. #9
    Registered User
    Join Date
    06-25-2009
    Location
    Los Angeles
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Excel/PowerPoint 2007 Right Click Menues

    Oh, that's super lame then! Is it possible to assign a macro to shortcut key then?

    Is there anything else I can do to run a macro, outside of a slideshow, and not use the ribbon bar?

    Thanks.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    10,944

    Re: Excel/PowerPoint 2007 Right Click Menues

    No Onkey in PPT as there is in excel.

    Your only, non riibbon, option in ppt is the QAT.
    Cheers
    Andy
    www.andypope.info

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0