none
Problems with GetVisible in a vsto2010 word 2010 addin RRS feed

  • Question

  • I am having problems getting the GetVisible to work in a vsto2010 word 2010 addin.
    Seems like this should be pretty simple.
    Ribbon1.xml & Ribbon1.vb included.

    Thanks in advance.

    Imports System.Diagnostics
    <Runtime.InteropServices.ComVisible(True)> _
    Public Class Ribbon1
      Implements Office.IRibbonExtensibility
      Private ribbon As Office.IRibbonUI
      Private btn1State As Boolean = True
      Private btn2State As Boolean = True
      Public Sub New()
      End Sub
      Public Function GetCustomUI(ByVal ribbonID As String) As String _
          Implements Office.IRibbonExtensibility.GetCustomUI
        Return GetResourceText("XML_RibbonTesting.Ribbon1.xml")
      End Function
    #Region "Ribbon Callbacks"
      Public Sub Ribbon_Load(ByVal ribbonUI As Office.IRibbonUI)
        Me.ribbon = ribbonUI
      End Sub
      Public Sub buttonClick(ByVal control As Office.IRibbonControl)
        Debug.Print(control.Id)
      End Sub
      Public Sub GetVisible(ByVal control As Office.IRibbonControl, ByRef returnedVal As Boolean)
        Debug.Print("GetVisible called with control.id =" & control.Id)
        Select Case control.Id
          Case "btn1" : returnedVal = btn1State
          Case "btn2" : returnedVal = btn2State
        End Select
      End Sub
    #End Region
    #Region "Helpers"
      Private Shared Function GetResourceText(ByVal resourceName As String) As String
        Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
        Dim resourceNames() As String = asm.GetManifestResourceNames()
        For i As Integer = 0 To resourceNames.Length - 1
          If String.Compare(resourceName, resourceNames(i), StringComparison.OrdinalIgnoreCase) = 0 Then
            Using resourceReader As IO.StreamReader = New IO.StreamReader(asm.GetManifestResourceStream(resourceNames(i)))
              If resourceReader IsNot Nothing Then
                Return resourceReader.ReadToEnd()
              End If
            End Using
          End If
        Next
        Return Nothing
      End Function
    #End Region
    End Class
    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab id="TabTest" label ="TabTest" insertBeforeQ="TabHome">
            <group id="GroupTest" label="GroupTest">
              <button id="btn1" label="btn1" onAction ="buttonClick" getVisible="GetVisible" />
              <button id="btn2" label="btn2" onAction="buttonClick" getVisible="GetVisible" />
              <button id="btn3" label="btn3" onAction ="buttonClick" />
              <button id="btn4" label="btn4" onAction="buttonClick" />
            </group>
          </tab>
        
        </tabs>
      </ribbon>
    </customUI>


    Tim

    Wednesday, March 28, 2012 1:52 PM

Answers

  • Hi Tim,

    Thank you for posting.

    Because you use the VB.net,  I found that the callback GetVisible signature is wrong, try to modify like this:

       Public Function GetVisible(control As Office.IRibbonControl) As Boolean
            Dim returnedVal As Boolean
            Select Case control.Id
                Case "btn1" : returnedVal = btn1State
                Case "btn2" : returnedVal = btn2State
            End Select
    
            Return returnedVal
        End Function

    For more details, you can refer to this article:

    http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Tim_Shaf Thursday, March 29, 2012 1:12 PM
    Thursday, March 29, 2012 2:04 AM

All replies

  • Hi Tim,

    Thank you for posting.

    Because you use the VB.net,  I found that the callback GetVisible signature is wrong, try to modify like this:

       Public Function GetVisible(control As Office.IRibbonControl) As Boolean
            Dim returnedVal As Boolean
            Select Case control.Id
                Case "btn1" : returnedVal = btn1State
                Case "btn2" : returnedVal = btn2State
            End Select
    
            Return returnedVal
        End Function

    For more details, you can refer to this article:

    http://msdn.microsoft.com/en-us/library/aa722523(v=office.12).aspx

    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Tim_Shaf Thursday, March 29, 2012 1:12 PM
    Thursday, March 29, 2012 2:04 AM
  • Thanks Bruce
    I knew it was something simple.
    Works Great!!


    Tim

    Thursday, March 29, 2012 1:12 PM