none
Office Ribbon development : Automation error (n° 440) RRS feed

  • Question

  • Hello,

    I am programming a ribbon on Microsoft Project 2010. This software permit to generate a ribbon directly with VBA code without need to create a separate XLM file. The XML code is put on a string named here strXML and the XML code is added to the ribbon with the following command : ActiveProject.SetCustomUI (strXML)

    The following code generate an AUTOMATION ERROR (n° 440) when I click on the gallery button (after the VBA code have generated the ribbon without problem.)

    Does someone have I an idea to solve this problem ?

    Thanks a lot for your help.

    Best regards.

    Nicolas

    CODE:

        strXML = "<mso:customUI xmlns:mso=""http://schemas.microsoft.com/office/2009/07/customui"">"
        strXML = strXML & "<mso:ribbon>"
        strXML = strXML & "<mso:qat/>"
        strXML = strXML & "     <mso:tabs>"
        strXML = strXML & "     <mso:tab id=""PlannersTab"" label=""Planners"" insertBeforeQ=""mso:TabResource"">"
       
        strXML = strXML & "         <mso:group id=""GroupMove"" label=""Move"" autoScale=""true"">"     

        strXML = strXML & "         <mso:gallery  id=""MSN"" "
        strXML = strXML & "                label=""Go to MSN"" "
        strXML = strXML & "                imageMso=""MenuTaskWellArrange"" "
        strXML = strXML & "                size=""large"""

         strXML = strXML & "                columns=""3"" "
        strXML = strXML & "                rows=""10"" "

        strXML = strXML & "                getItemCount=""gallery_MSN_getItemCount"" "
        strXML = strXML & "                getItemLabel=""gallery_MSN_getItemLabels"" "
       
        strXML = strXML & "                showItemLabel=""true"" "
         
        strXML = strXML & "                onAction=""gallery_MSN_Click"" >"

        strXML = strXML & "          </mso:gallery>"

        strXML = strXML & "         </mso:group>"
        strXML = strXML & "     </mso:tab>"
        strXML = strXML & "     </mso:tabs>"
        strXML = strXML & "</mso:ribbon>"
        strXML = strXML & "</mso:customUI>"
       
    ActiveProject.SetCustomUI (strXML)

    Monday, August 13, 2012 3:08 PM

Answers

  • Hi Nicolas,

    There seems that you can't use "getItemCount"," getItemLabel" in VBA project. I rewrite your VBA project. It works fine on my side.

    Option Explicit
    
    Sub gallery_MSN_Click()
    
     'Call the macro that belongs to the label when you click one of the labels.
     'Example: When you click the first label it runs the macro named "macro_1".
         On Error Resume Next
         MsgBox ("It works !")
         On Error GoTo 0
    
    End Sub
    
    Private Sub AddHighlightRibbon()
        Dim ribbonXml As String
        Dim MyArray As Variant
        Dim item As Variant
        Dim cnt As Integer
        
        cnt = 0
        MyArray = Array("Sheila Webster", "Brian Main", "Susan Zhang", "Anne Walzer", "Andrea Vogel", "Ronda Viescas", _
               "Norman Harker", _
               "Michelle Wells", _
               "Wilma Yang", _
               "Angel Wang", _
               "Raymond Denny", _
               "June Winograd")
               
        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=""highlightTab"" label=""Highlight"" insertBeforeQ=""mso:TabFormat"">"
        ribbonXml = ribbonXml + "        <mso:group id=""testGroup"" label=""Test"" autoScale=""true"">"
        ribbonXml = ribbonXml + "         <mso:gallery  id=""MSN"" "
        ribbonXml = ribbonXml + "                label=""Go to MSN"" "
        ribbonXml = ribbonXml + "                imageMso=""MenuTaskWellArrange"" "
        ribbonXml = ribbonXml + "                size=""large"""
        ribbonXml = ribbonXml + "                columns=""3"" "
        ribbonXml = ribbonXml + "                rows=""10"" "
        ribbonXml = ribbonXml + "                showItemLabel=""true"" "
        ribbonXml = ribbonXml + "                onAction=""gallery_MSN_Click"" >"
        For Each item In MyArray
            ribbonXml = ribbonXml + "               <mso:item id=""item" + CStr(cnt) + """ label=""" + item + """></mso:item>"
            cnt = cnt + 1
        Next
        ribbonXml = ribbonXml + "               <mso:item id=""item01"" label=""ddd""></mso:item>"
        ribbonXml = ribbonXml + "          </mso:gallery>"
        ribbonXml = ribbonXml + "        </mso:group>"
        ribbonXml = ribbonXml + "      </mso:tab>"
        ribbonXml = ribbonXml + "    </mso:tabs>"
        ribbonXml = ribbonXml + "  </mso:ribbon>"
        ribbonXml = ribbonXml + "</mso:customUI>"
        
        Debug.Print ribbonXml
        ActiveProject.SetCustomUI (ribbonXml)
    End Sub
    
    Sub test()
        Dim strXML As String
        strXML = "<mso:customUI xmlns:mso=""http://schemas.microsoft.com/office/2009/07/customui"">"
         strXML = strXML & "<mso:ribbon>"
         strXML = strXML & "<mso:qat/>"
         strXML = strXML & "     <mso:tabs>"
         strXML = strXML & "     <mso:tab id=""PlannersTab"" label=""Planners"" insertBeforeQ=""mso:TabResource"">"
         
         strXML = strXML & "         <mso:group id=""GroupMove"" label=""Move"" autoScale=""true"">"
    
    
    
        strXML = strXML & "         <mso:gallery  id=""MSN"" "
         strXML = strXML & "                label=""Go to MSN"" "
         strXML = strXML & "                imageMso=""MenuTaskWellArrange"" "
         strXML = strXML & "                size=""large"""
    
         'strXML = strXML & "                columns=""3"" "
         'strXML = strXML & "                rows=""10"" "
    
        strXML = strXML & "                getItemCount=""gallery_MSN_getItemCount"" "
         strXML = strXML & "                getItemLabel=""gallery_MSN_getItemLabels"" "
         
         strXML = strXML & "                showItemLabel=""true"" "
          
         strXML = strXML & "                onAction=""gallery_MSN_Click"" >"
    
        strXML = strXML & "          </mso:gallery>"
    
    
        strXML = strXML & "         </mso:group>"
         strXML = strXML & "     </mso:tab>"
         strXML = strXML & "     </mso:tabs>"
         strXML = strXML & "</mso:ribbon>"
         strXML = strXML & "</mso:customUI>"
         
     ActiveProject.SetCustomUI (strXML)
    
    End Sub

    However, I think it meaningless for you. If you want to use this control, you need to find out a channel to send the information which you clicked upon. I would suggest your create a COM add-in instead of VBA project to handle your issue.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, August 15, 2012 7:03 AM
    Moderator

All replies

  • Hello,

    I am programming a ribbon on Microsoft Project 2010.

    The ribbon appear.

     But, when I click on an element, as a button for example, to realize an action, an error message appear : Automation error (Error 440)

    Does someone have an idea to solve this problem ?

    The Code in below.

    Thanks

    Nicolas

    Public Sub Affichage_gfgfggfggRuban()

    ' Clear customized ribbons
    strXML = "<mso:customUI xmlns:mso=""<mso:ribbon></mso:ribbon></mso:customUI">http://schemas.microsoft.com/office/2009/07/customui""><mso:ribbon></mso:ribbon></mso:customUI>"
    ActiveProject.SetCustomUI (strXML)


    'Create NewRibbon

        'strXML = "<mso:customUI xmlns:mso=""<mso:ribbon><mso:tabs><mso:tab">http://schemas.microsoft.com/office/2009/07/customui""><mso:ribbon><mso:tabs><mso:tab id=""PlannersTab"" label=""Planners"" insertBeforeQ=""mso:TabResource""><mso:group label=""Nouveau groupe"" autoScale=""true""/></mso:tab></mso:tabs></mso:ribbon></mso:customUI>"
        strXML = "<mso:customUI xmlns:mso=""http://schemas.microsoft.com/office/2009/07/customui"">"
        strXML = strXML & "<mso:ribbon>"
        strXML = strXML & "     <mso:tabs>"
        strXML = strXML & "     <mso:tab id=""PlannersTab"" label=""Planners"" insertBeforeQ=""mso:TabResource"">"

        strXML = strXML & "         <mso:group id=""GroupMove"" label=""Move"" autoScale=""true"">" 'Ne pas fermer les groupes

        strXML = strXML & "         <mso:button id=""trest"" label=""hh"" onAction=""TESTBUTTON"""

        strXML = strXML & " />"

        strXML = strXML & "         </mso:group>"
        strXML = strXML & "     </mso:tab>"
        strXML = strXML & "     </mso:tabs>"
        strXML = strXML & "</mso:ribbon>"
        strXML = strXML & "</mso:customUI>"

    ActiveProject.SetCustomUI (strXML)     ' MS Project function that permit to add the custom ribbon xml code on the ribbon file.

    End Sub


    Public Sub TESTBUTTON(ByVal control As Office.IRibbonControl)

    MsgBox ("ok")

    End Sub

    Friday, August 3, 2012 11:48 AM
  • Hi NCITL,

    Thanks for posting in the MSDN Forum.

    strXML = "<mso:customUI xmlns:mso=""<mso:ribbon></mso:ribbon></mso:customUI">http://schemas.microsoft.com/office/2009/07/customui""><mso:ribbon></mso:ribbon></mso:customUI>"

    Please check it. There have many mistakes.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 7, 2012 5:02 AM
    Moderator
  • Hi Nicolas,

    Thanks for postig in the MSDN Forum.

    The snippet which you provided works fine on my side. I think you need provide more information for troubleshooting.

    I use Windows Server 2008 R2 MSProject 14.0.6112.5000 (32-bit)

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 14, 2012 6:55 AM
    Moderator
  • Hi Tom,

    Thanks for your answer.

    I have forgottent to give the rest of the code that link the ribbon to VBA code (i have added it under).

    I think the problem come from this part of the code.

    Some more details: On the ribbon, when I click on the icon, the choices that should appear with a gallery control doesn't appear and, on the same time, the AUTOMATION ERROR message appear (440).

    (I use Windows 7 64bits and Office 2010)

    If you need more information about the problem, don't hesitate to post.

    Thanks for your help.

    Nicolas

    Rest of the code:

    Sub gallery_MSN_getItemCount(control As IRibbonControl, ByRef returnedVal)
       
        On Error Resume Next
        returnedVal = 12

    End Sub

    Public Sub gallery_MSN_getItemLabels(control As IRibbonControl, index As Integer, ByRef returnedVal)
    'This callback runs for every item (label).
    'This example uses the values in the array for Label names.
      
        Dim Labelname As Variant
        On Error Resume Next
        Labelname = _
        Array("Sheila Webster", _
              "Brian Main", _
              "Susan Zhang", _
              "Anne Walzer", _
              "Andrea Vogel", _
              "Ronda Viescas", _
              "Norman Harker", _
              "Michelle Wells", _
              "Wilma Yang", _
              "Angel Wang", _
              "Raymond Denny", _
              "June Winograd")

        On Error Resume Next
        returnedVal = Labelname(index)
        On Error GoTo 0


    End Sub

    Sub gallery_MSN_Click(control As IRibbonControl, id As String, index As Integer)

    'Call the macro that belongs to the label when you click one of the labels.
    'Example: When you click the first label it runs the macro named "macro_1".
        On Error Resume Next
        msgbox("It works !")    On Error GoTo 0

    End Sub

    Tuesday, August 14, 2012 10:25 AM
  • Some more details:

    it appear that between Office 2007 and Office 2010, the CALLBACK methods of the ribbon have changed:

    For exemple, the callback of a button object was on Office 2007

          Sub rxbtn_Click(control As IRibbonControl)

               CODE

          End sub

    and become on Office 2010

          Sub rxbtn_Click()

               CODE

          End sub

    If I put the "control As IRibbonControl" on Office 2010, it generate the same error message that for the gallery object (Automation Error: 440).

    Source: http://msdn.microsoft.com/en-us/library/ee767705(office.14).aspx

    Unfortunately, this article talk only about a button object but not about more complex objects as the gallery object for example that I would like to use ...

    Does someone know how to proceed with the CALLBACKS for a galery object to avoid the error ?

    Thanks

     

    Tuesday, August 14, 2012 3:39 PM
  • Hi Nicolas,

    There seems that you can't use "getItemCount"," getItemLabel" in VBA project. I rewrite your VBA project. It works fine on my side.

    Option Explicit
    
    Sub gallery_MSN_Click()
    
     'Call the macro that belongs to the label when you click one of the labels.
     'Example: When you click the first label it runs the macro named "macro_1".
         On Error Resume Next
         MsgBox ("It works !")
         On Error GoTo 0
    
    End Sub
    
    Private Sub AddHighlightRibbon()
        Dim ribbonXml As String
        Dim MyArray As Variant
        Dim item As Variant
        Dim cnt As Integer
        
        cnt = 0
        MyArray = Array("Sheila Webster", "Brian Main", "Susan Zhang", "Anne Walzer", "Andrea Vogel", "Ronda Viescas", _
               "Norman Harker", _
               "Michelle Wells", _
               "Wilma Yang", _
               "Angel Wang", _
               "Raymond Denny", _
               "June Winograd")
               
        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=""highlightTab"" label=""Highlight"" insertBeforeQ=""mso:TabFormat"">"
        ribbonXml = ribbonXml + "        <mso:group id=""testGroup"" label=""Test"" autoScale=""true"">"
        ribbonXml = ribbonXml + "         <mso:gallery  id=""MSN"" "
        ribbonXml = ribbonXml + "                label=""Go to MSN"" "
        ribbonXml = ribbonXml + "                imageMso=""MenuTaskWellArrange"" "
        ribbonXml = ribbonXml + "                size=""large"""
        ribbonXml = ribbonXml + "                columns=""3"" "
        ribbonXml = ribbonXml + "                rows=""10"" "
        ribbonXml = ribbonXml + "                showItemLabel=""true"" "
        ribbonXml = ribbonXml + "                onAction=""gallery_MSN_Click"" >"
        For Each item In MyArray
            ribbonXml = ribbonXml + "               <mso:item id=""item" + CStr(cnt) + """ label=""" + item + """></mso:item>"
            cnt = cnt + 1
        Next
        ribbonXml = ribbonXml + "               <mso:item id=""item01"" label=""ddd""></mso:item>"
        ribbonXml = ribbonXml + "          </mso:gallery>"
        ribbonXml = ribbonXml + "        </mso:group>"
        ribbonXml = ribbonXml + "      </mso:tab>"
        ribbonXml = ribbonXml + "    </mso:tabs>"
        ribbonXml = ribbonXml + "  </mso:ribbon>"
        ribbonXml = ribbonXml + "</mso:customUI>"
        
        Debug.Print ribbonXml
        ActiveProject.SetCustomUI (ribbonXml)
    End Sub
    
    Sub test()
        Dim strXML As String
        strXML = "<mso:customUI xmlns:mso=""http://schemas.microsoft.com/office/2009/07/customui"">"
         strXML = strXML & "<mso:ribbon>"
         strXML = strXML & "<mso:qat/>"
         strXML = strXML & "     <mso:tabs>"
         strXML = strXML & "     <mso:tab id=""PlannersTab"" label=""Planners"" insertBeforeQ=""mso:TabResource"">"
         
         strXML = strXML & "         <mso:group id=""GroupMove"" label=""Move"" autoScale=""true"">"
    
    
    
        strXML = strXML & "         <mso:gallery  id=""MSN"" "
         strXML = strXML & "                label=""Go to MSN"" "
         strXML = strXML & "                imageMso=""MenuTaskWellArrange"" "
         strXML = strXML & "                size=""large"""
    
         'strXML = strXML & "                columns=""3"" "
         'strXML = strXML & "                rows=""10"" "
    
        strXML = strXML & "                getItemCount=""gallery_MSN_getItemCount"" "
         strXML = strXML & "                getItemLabel=""gallery_MSN_getItemLabels"" "
         
         strXML = strXML & "                showItemLabel=""true"" "
          
         strXML = strXML & "                onAction=""gallery_MSN_Click"" >"
    
        strXML = strXML & "          </mso:gallery>"
    
    
        strXML = strXML & "         </mso:group>"
         strXML = strXML & "     </mso:tab>"
         strXML = strXML & "     </mso:tabs>"
         strXML = strXML & "</mso:ribbon>"
         strXML = strXML & "</mso:customUI>"
         
     ActiveProject.SetCustomUI (strXML)
    
    End Sub

    However, I think it meaningless for you. If you want to use this control, you need to find out a channel to send the information which you clicked upon. I would suggest your create a COM add-in instead of VBA project to handle your issue.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, August 15, 2012 7:03 AM
    Moderator
  • Hi Tom,

    Thank you for your answer. The code that you put on the thread for fine also on my computer.

    How I can create an add-in for Office Project 2010 ? Does I need to use Visual Studio? If yes, does it is possible to use the free  EXPRESS edition?

    Thanks for your help.

    Have a good day.

    Nicolas

    Friday, August 17, 2012 7:05 AM
  • Hi Nicolas

    <<How I can create an add-in for Office Project 2010 ? Does I need to use Visual Studio? If yes, does it is possible to use the free  EXPRESS edition?>>

    You can use either the VSTO tool or the "Shared Add-in" template to create an Add-in that works in Office. VSTO is definitely not available in the Express edition - it's only part of the more "professional" versions of Visual Studio.

    "Shared Add-in" doesn't appear to be part of Express 2010; I can't remember whether it was in earlier versions. But in any case the licensing terms for Express would not allow you to distribute it.


    Cindy Meister, VSTO/Word MVP

    Sunday, August 19, 2012 4:15 PM
    Moderator