none
Custom Ribbon OnAction command RRS feed

  • Question

  • I have the following code in an Outlook Ribbon Customisation Project (it writes lines to an XML file)...

            XMLWriter.WriteStartElement("button")
            XMLWriter.WriteAttributeString("id", "buttonTrial")
            XMLWriter.WriteAttributeString("label", "Trial")
            XMLWriter.WriteAttributeString("size", "large")
            XMLWriter.WriteAttributeString("WHAT GOES HERE", "AND WHAT GOES HERE???")
            XMLWriter.WriteEndElement()

    I then have the following... (what I want to run when the 'Trial' button is clicked)...

        Public Sub ButtonClick()
            MsgBox("Hello")
        End Sub

    What do I put in the last XML attribute to get this code to run?

    Jacob



    • Edited by Jakethepeg1 Thursday, April 18, 2013 11:27 AM
    Thursday, April 18, 2013 11:24 AM

Answers

All replies

  • You want to end up with this:
     
        onAction="ButtonClick"

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Jakethepeg1" <=?utf-8?B?SmFrZXRoZXBlZzE=?=> wrote in message news:33f873bd-3262-4dff-bb95-a494ec2d7cfd...

    I have the following code in an Outlook Ribbon Customisation Project (it writes lines to an XML file)...

            XMLWriter.WriteStartElement("button")
            XMLWriter.WriteAttributeString("id", "buttonTrial")
            XMLWriter.WriteAttributeString("label", "Trial")
            XMLWriter.WriteAttributeString("size", "large")
            XMLWriter.WriteAttributeString("WHAT GOES HERE", "AND WHAT GOES HERE???")
            XMLWriter.WriteEndElement()

    I then have the following... (what I want to run when the 'Trial' button is clicked)...

        Public Sub ButtonClick()
            MsgBox("Hello")
        End Sub

    What do I put in the last XML attribute to get this code to run?

    Jacob




    Ken Slovak MVP - Outlook
    Thursday, April 18, 2013 2:03 PM
    Moderator
  • Thanks.

    This was what I tried originally and it doesn't work.

    I've changed my approach slightly... this is my Addin Code...

    Public Class ThisAddIn
    
        Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
            Return New LoadCustomRibbon()
        End Function
    
        Public Sub ButtonClick()
            MsgBox("Hello")
        End Sub
    
    End Class
    
    
    <Runtime.InteropServices.ComVisible(True)> _
    Public Class LoadCustomRibbon
        Implements Office.IRibbonExtensibility
    
        Private ribbon As Office.IRibbonUI
    
        Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Office.IRibbonExtensibility.GetCustomUI
    
            Dim XMLText As String = System.IO.File.ReadAllText("C:\OutlookFilingAddin\Current.xml")
            Return XMLText.ToString
    
        End Function
    
    End Class

    And this is the XML file I am loading...

    <?xml version="1.0" encoding="utf-8"?>
    <customUI
      onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
      <ribbon>
        <tabs>
          <tab
            idMso="TabMail">
            <group
              id="GroupNewItems"
              label="Trial">
              <button
                id="buttonTrial"
                label="Trial"
                size="large"
                onAction="ButtonClick" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    The group and button show on the ribbon, just that when you click it nothing happens...

    What am I doing wrong?

    Jacob

    Thursday, April 18, 2013 5:59 PM
  • You need to provide the correct signature for your onAction callback. In VB.NET that would be this:
     
    Public Sub ButtonClick(ByVal control As Office.IRibbonControl)
        ' control.Context can be cast as the Inspector that has the item where the click occurred
        ' control.Id is the id of the button that fired the click callback
     
    End Sub
     

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Jakethepeg1" <=?utf-8?B?SmFrZXRoZXBlZzE=?=> wrote in message news:4eb38206-04f3-47d7-b0e0-43d897d43787...

    Thanks.

    This was what I tried originally and it doesn't work.

    I've changed my approach slightly... this is my Addin Code...

    Public Class ThisAddIn
    
        Protected Overrides Function CreateRibbonExtensibilityObject() As Microsoft.Office.Core.IRibbonExtensibility
            Return New LoadCustomRibbon()
        End Function
    
        Public Sub ButtonClick()
            MsgBox("Hello")
        End Sub
    
    End Class
    
    
    <Runtime.InteropServices.ComVisible(True)> _
    Public Class LoadCustomRibbon
        Implements Office.IRibbonExtensibility
    
        Private ribbon As Office.IRibbonUI
    
        Public Function GetCustomUI(ByVal ribbonID As String) As String Implements Office.IRibbonExtensibility.GetCustomUI
    
            Dim XMLText As String = System.IO.File.ReadAllText("C:\OutlookFilingAddin\Current.xml")
            Return XMLText.ToString
    
        End Function
    
    End Class

    And this is the XML file I am loading...

    <?xml version="1.0" encoding="utf-8"?>
    <customUI
      onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2009/07/customui">
      <ribbon>
        <tabs>
          <tab
            idMso="TabMail">
            <group
              id="GroupNewItems"
              label="Trial">
              <button
                id="buttonTrial"
                label="Trial"
                size="large"
                onAction="ButtonClick" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    The group and button show on the ribbon, just that when you click it nothing happens...

    What am I doing wrong?

    Jacob


    Ken Slovak MVP - Outlook
    Thursday, April 18, 2013 6:21 PM
    Moderator
  • Thanks,

    Please excuse my limited knowledge on this topic: I updated the code as follows...what am I missing now?

        Public Sub ButtonClick(ByVal control As Office.IRibbonControl)
            MsgBox(control.Id)
        End Sub

    Jacob

    Thursday, April 18, 2013 6:51 PM
  • buttonclick must be a method defined on ribbon class, not thisaddin. also method signature should match. look here http://msdn.microsoft.com/en-us/library/vstudio/aa722523.aspx
    • Marked as answer by Jakethepeg1 Monday, April 22, 2013 11:46 PM
    Friday, April 19, 2013 4:31 AM
  • define buttonclick on ribbon class, not thisaddin
    • Marked as answer by Jakethepeg1 Monday, April 22, 2013 11:46 PM
    Friday, April 19, 2013 4:32 AM
  • buttonclick must be a method defined on ribbon class, not thisaddin. also method signature should match.

    Many Thanks.

    This was driving me crazy until I read your post. I moved my Sub code into MyRibbon.vb and it worked!! 

    Regards, Stephen

    Tuesday, March 31, 2015 3:11 PM