Forum Discussion
Adding a ComboBox to a MS Project Ribbon
What are you doing wrong? That's hard to say since you don't give us the main essence of your code. For example I don't see any reference to the mso:customUI element which must be part of the XML string. Nor do I see the mso:ribbon element. Both of these items are requirements of the Project.SetCusomUI Method (ref: Project.SetCustomUI method (Project) | Microsoft Learn).
However, full disclosure, I have not done any VBA programming that uses XML strings, so my ability to help resolve your issue is limited. But I do agree, modifying the Project UI was much easier in older versions (i.e. before the ribbon was introduced in Project 2010).
John
All of the code shown was within a set of custom UI code that was already working. I am only showing the added portion that caused the code to not work. For your reference though, here is the entirety of the code with the working portions removed.
Dim ribbonXml As String
On Error Resume Next
ribbonXml = "<mso:customUI xmlns:mso=""http://schemas.microsoft.com/office/2009/07/customui"">"
ribbonXml = ribbonXml + " <mso:ribbon>"
ribbonXml = ribbonXml + " <mso:tabs>"
ribbonXml = ribbonXml + " <mso:tab id=""TestTab"" label=""TAB NAME"" insertBeforeQ=""mso:TabFormat"">"
'***** WORKING CODE REMOVED *****
'***** QUICK LABELS *****
ribbonXml = ribbonXml + " <mso:group id=""grpLabel"" label=""Quick Labels"" autoScale=""true"">"
ribbonXml = ribbonXml + " <comboBox id=""cboLabels"" label=""Labels"" onChange=""TestRibbon"">"
ribbonXml = ribbonXml + " <item id=""lblAdd"" label=""Add"" />"
ribbonXml = ribbonXml + " <item id=""lblDel"" label=""Delete"" />"
ribbonXml = ribbonXml + " <item id=""lblChg"" label=""Change"" />"
ribbonXml = ribbonXml + " </comboBox>"
'***** WORKING CODE REMOVED *****
ribbonXml = ribbonXml + " </mso:tab>"
ribbonXml = ribbonXml + " </mso:tabs>"
ribbonXml = ribbonXml + " </mso:ribbon>"
ribbonXml = ribbonXml + "</mso:customUI>"
ActiveProject.SetCustomUI (ribbonXml)
I followed code that came straight out of Microsoft's and other's sites regarding adding a combo box to the Ribbon UI. However, I still cannot get it to work.
- John-projectOct 14, 2022Silver Contributor
It might have been helpful to also see the part of your code that does work. Nonetheless, when I tried the code in Project 2019 indeed nothing happens, no error messages and no changes to the GUI. However, when I tried your code using Project 2010 I got two error messages:
and after hitting the "OK" button I got this additional message:
Not being savvy with XML I don't know what it all means but perhaps it provides a clue for you.
I also wondered if there is some object library reference that needs to be set to let your code run. On the sites where you got the code, did they mention anything about object library references?
I'll keep looking into it and let you know if I find anything else.
John
- kepidogoOct 20, 2022Copper Contributor
John-project I was able to get it to work. I just had to add "mso:" to the front of every XML line...
ribbonXml = ribbonXml + " <mso:group id=""grpLabel"" label=""Quick Labels"" autoScale=""true"">" ribbonXml = ribbonXml + " <mso:comboBox id=""cboLabels"" label=""Labels"" onChange=""TestRibbon"">" ribbonXml = ribbonXml + " <mso:item id=""lblAdd"" label=""Add"" />" ribbonXml = ribbonXml + " <mso:item id=""lblDel"" label=""Delete"" />" ribbonXml = ribbonXml + " <mso:item id=""lblChg"" label=""Change"" />" ribbonXml = ribbonXml + " <mso:item id=""lblClsd"" label=""Closed"" />" ribbonXml = ribbonXml + " </mso:comboBox>"
So now I have a visible Combo Box on the Ribbon, but what does the code look like to capture the selected value?
- John-projectOct 21, 2022Silver Contributorkepidogo,
I tried running your modified code and all I get is a flash in the ribbon when I hit the "ActiveProject.SetCustomUI(ribbonXml) line. If I comment out everything in the "<mso:group...> I do get NEW TAB added but that's it. I can't even get a new group under the tab.
Just curious, what references do you have set?
John
- John-projectOct 13, 2022Silver Contributorkepidogo,
Thanks for the more complete info, I'll take a look at it over the weekend. But just for reference, it won't be the first time code shown on a Microsoft site doesn't work "as advertised". For example, I recently looked at MS documentation on the Application.ChangeIcon Method. The article talks about an "Object" command on the ribbon but that command doesn't exist for Project 2019.
John