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

  • Question

  • The below returns system.__comObject

    Public Module upperCase
        Sub doUpperCase()
        End Sub

    End Module

    • Changed type Calvin_Gao Wednesday, February 22, 2012 2:54 AM it's a question
    Tuesday, February 21, 2012 11:54 AM


  • 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
                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)
                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

    • Marked as answer by Calvin_Gao Thursday, March 8, 2012 9:51 AM
    Wednesday, February 22, 2012 2:54 AM