Forum Discussion
Adding a ComboBox to a MS Project Ribbon
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.
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