MS Project - 宏在 XML 自定义选项卡上不起作用

MS Project - Macro not working on XML custom tab

我正在使用 VBA 和 XML 在 MS Project 中创建自定义选项卡。在 ProjectGlobal 我有以下内容:

里面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

然后我有一个包含以下内容的模块

Sub newProjectPN()

MsgBox "Not working yet. Please be patient :)"

End Sub

它按预期创建了带有按钮的选项卡,但是当我单击该按钮时它什么也没做。如何在 XML 个字符串中引用宏?

我找到了解决办法。我在 XML 代码中使用了两个不同的名称空间。这就是我现在所拥有的并且它有效。我还将按钮 ID 从 idQ 更改为 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