Problem in using Information.TypeName Method with XL Application's Selection object

Vikasbhandari2

New member
Joined
Mar 31, 2009
Messages
3
Hi Cindy,

I am creating a simple VB.Net Excel Addin, where in I am trying to Trap the Selection Type. I am trying the function after clicking a button in the Ribbon. And I am using Ribbon Designer for this. Not sure if it does create any difference. The Ribbon designer has the following Event handler:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) Handles Button1.Click
        MsgBox("Button Clicked", MsgBoxStyle.Critical, "Success!!")
        Dim app As Application = Globals.ThisAddIn.Application

        Dim selType As String

        Dim typ As Type

        Dim strName As String
        strName = ""
        Dim sels As Object
        Dim proxy As XLAppProxy

        proxy = XLAppProxy.GetApplication()
        sels = TryCast(app.Selection, Object)

        Try
            selType = Information.TypeName(app.Selection)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Hello")
        End Try
    End Sub

Now, when the line "selType = Information.TypeName(app.Selection)" is executed, I get the following exception : "The interface does not support late bound calls since it does not derive from IDispatch." The type of exception is System.Reflection.TargetInvocationException.

Hope to get a reply soon.

Thanks,
Vikas
 
Back
Top