Forum Discussion

kepidogo's avatar
kepidogo
Copper Contributor
Oct 11, 2022

Adding a ComboBox to a MS Project Ribbon

Currently, I am using Project 2019. I created a custom ribbon using VBA code that creates an XML string and is activated using the following code:

ActiveProject.SetCustomUI (ribbonXml)

I tried to add a ComboBox to the ribbon using the following code:

    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>"
    ribbonXml = ribbonXml + "        </mso:group>"

 

The ribbon works fine before adding this code. Once this code is added, the ribbon fails to load. I thought adding the onAction property was causing this but that did not change anything. The code above was just to get the combo box to appear. I would add the rest of the properties later.

 

What am I doing wrong? Is Microsoft going to do anything to make this easier? Creating custom UIs should not be this hard to do.

 

Thank you in advance!

6 Replies

  • John-project's avatar
    John-project
    Silver Contributor

    kepidogo 

    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

    • kepidogo's avatar
      kepidogo
      Copper Contributor

      John-project

      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-project's avatar
        John-project
        Silver Contributor

        kepidogo 

        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

Resources