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!
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.
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!
can you post the code or workbook
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.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
Thanks
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
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?
defunct = not possible
Maybe this will make it clearer.
The AddContextMenu routine will add a new item to the named context menu.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
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.
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.
No Onkey in PPT as there is in excel.
Your only, non riibbon, option in ppt is the QAT.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks