none
How do i get the active range of selected cells in VSTO VB.Net Excel Addin

    Question

  • The below returns system.__comObject

    Public Module upperCase
        Sub doUpperCase()
            MsgBox(Globals.ThisAddIn.Application.Selection.ToString)
        End Sub

    End Module

    Tuesday, February 21, 2012 11:54 AM

Answers

  • Hi,

    The following code should help:

        Sub doUpperCase()
            Dim rng As Excel.Range
            'convert selection to range object
            rng = CType(Globals.ThisAddIn.Application.Selection, Excel.Range)
            If Not rng Is Nothing Then
                'show selection address
                MsgBox(rng.Address)
                If rng.Count > 1 Then
                    'if there are more than one cell selected, only show value of the first cell
                    MsgBox(rng(1, 1).Value)
                Else
                    MsgBox(rng.Value)
                End If
            End If
        End Sub

    In addition, I'm going to change type of this thread to a question.

    Good day,


    Calvin Gao[MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, February 22, 2012 2:54 AM