I'm creating a custom tab in MS Project using VBA and XML. On the ProjectGlobal
I have the following:
Inside ThisProject(Global.MPT)
Private Sub Project_Activate(ByVal pj As MSProject.Project)
ribbonXml = "<mso:customUI xmlns:x1=""http://schemas.microsoft.com/office/2009/07/customui/macro"" xmlns:mso=""http://schemas.microsoft.com/office/2009/07/customui"">"
ribbonXml = ribbonXml + "<mso:ribbon>"
ribbonXml = ribbonXml + "<mso:qat/>"
ribbonXml = ribbonXml + "<mso:tabs>"
ribbonXml = ribbonXml + "<mso:tab id=""mso_c1.497B55B8"" label=""Produtos Novos"">"
ribbonXml = ribbonXml + "<mso:group id=""mso_c2.497B55B8"" label=""New Product"" imageMso=""ViewGoForward"" autoScale=""true"">"
ribbonXml = ribbonXml + "<mso:button idQ=""x1:newProjectPN"" label=""New Project (NOK)"" imageMso=""CategoryCollapse"" onAction=""thisproject.newProjectPN"" visible=""true"" />"
ribbonXml = ribbonXml + "</mso:group>"
ribbonXml = ribbonXml + "</mso:tab>"
ribbonXml = ribbonXml + "</mso:tabs>"
ribbonXml = ribbonXml + "</mso:ribbon>"
ribbonXml = ribbonXml + "</mso:customUI>"
ActiveProject.SetCustomUI (ribbonXml)
End Sub
Then I have a module with the following
Sub newProjectPN()
MsgBox "Not working yet. Please be patient :)"
End Sub
It creates the tab with the button as expected, but when I click the button it does nothing. How do I reference the macro in XML strings?
I've found the solution. I was using two different namespaces in the XML code. This is what I have now and it works. I've also changed the button id from idQ
to id
.
Private Sub Project_Activate(ByVal pj As MSProject.Project)
ribbonXml = "<mso:customUI xmlns:mso=""http://schemas.microsoft.com/office/2009/07/customui"">"
ribbonXml = ribbonXml + "<mso:ribbon>"
ribbonXml = ribbonXml + "<mso:qat/>"
ribbonXml = ribbonXml + "<mso:tabs>"
ribbonXml = ribbonXml + "<mso:tab id=""mso_c1.497B55B8"" label=""Produtos Novos"">"
ribbonXml = ribbonXml + "<mso:group id=""mso_c2.497B55B8"" label=""New Product"" imageMso=""ViewGoForward"" autoScale=""true"">"
ribbonXml = ribbonXml + "<mso:button id=""newProjectPN"" label=""New Project (NOK)"" imageMso=""CategoryCollapse"" onAction=""thisproject.newProjectPN"" visible=""true"" />"
ribbonXml = ribbonXml + "</mso:group>"
ribbonXml = ribbonXml + "</mso:tab>"
ribbonXml = ribbonXml + "</mso:tabs>"
ribbonXml = ribbonXml + "</mso:ribbon>"
ribbonXml = ribbonXml + "</mso:customUI>"
ActiveProject.SetCustomUI (ribbonXml)
End Sub