Search code examples
vbams-officems-project

MS Project VBA: Automation error when using custom ribbon buttons


I am trying to get a simple custom ribbon button working in MS Project and seem to be getting an "Automation Error: Exception Occured" whenever I actually click the button. I do not have any "Debug" option on the error message, leading me to believe this is something internal causing the issue.

I followed a tutorial online, and everything seems straightforward enough but I cant seem to figure out why it is not working on my end.

The ribbon button is added when the project is first opened (this works correctly)

Private Sub Project_Open(ByVal pj As MSProject.Project)
On Error GoTo Open_Error
    AddTestRibbon
Exit Sub
Open_Error:
    MsgBox Err.Description
End Sub

Here is the sub that adds actually adds the ribbon

Private Sub AddTestRibbon()
    Dim customUiXml As String
 
    customUiXml = "<mso:customUI xmlns:mso=""http://schemas.microsoft.com/office/2009/07/customui"">" _
        & "<mso:ribbon><mso:tabs><mso:tab id=""rtpTab"" label=""RTP"" " _
        & "insertBeforeQ=""mso:TabView"">" _
        & "<mso:group id=""group1"" label=""Tools"">" _
        & "<mso:button id=""viewTasksBtn"" label=""View Synchronized Tasks"" size=""large"" " _
        & "imageMso=""GetExternalDataFromText"" onAction=""Macro10"" />" _
        & "</mso:group></mso:tab></mso:tabs></mso:ribbon></mso:customUI>"
 
    ActiveProject.SetCustomUI (customUiXml)
End Sub

And here is the "OnAction" sub. From what I can tell we do not actually get here as the error is an internal automation error

Sub Macro10(control As IRibbonControl)

    Debug.Print "Clicked"

End Sub

And here is the error message that is shown (this error message is not caught by VBA, I have it set to break on all errors and it is not breaking at any point) Error Message

Thanks in advance for any help, I am a programmer (c++ primarily) but VBA/office is definitely not my strong suit and it is likely I am doing something stupid

I have tried following other tutorials/read the documentation but they unfortunately all lead to the same result.


Solution

  • After doing some tinkering and being pointed in some good directions from the comments, I found that removing "control As IRibbonControl" parameter from my "onAction" procedure resolved my issue and the button is now working as expected.

    The final code for Macro10 is now:

    Sub Macro10()
    
        Debug.Print "Clicked"
    
    End Sub