MKhare

I'm surprised that there is no straightforward call in VSTO for this.
I am trying to get the range of cells that have been selected by the user, i.e. after user has selected a region of cells using the mouse.
This is the closest I came:

Globals.Sheet2.Application.ActiveCell

This only gives me the range object corresponding to the first cell on the top left of selection.
Thanks in advance...

Maneesh


Re: Visual Studio Tools for Office Range for user selection in a sheet

MKhare

OK, this is another lead I got. Kind of a workaround;
I've written this code for 'SelectionChange' event of Workbook

Private Sub ThisWorkbook_SheetSelectionChange(ByVal Sh As System.Object, ByVal Target As Microsoft.Office.Interop.Excel.Range) Handles Me.SheetSelectionChange
'I'm writing to statusbar
Me.Application.StatusBar = Me.Name & ":" & _
Target.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlR1C1)
End Sub


ReferenceStyle:=Excel.XlReferenceStyle.xlR1C1
gives addresses in 'R1C2:R4C56,R23C4:R48C4' form

ReferenceStyle:=Excel.XlReferenceStyle.xlR1C1
gives addresses in '$A$15EmbarrassedF$28,$H$3EmbarrassedJ$9' form
if you see smilies in the post, they are actually colons




Re: Visual Studio Tools for Office Range for user selection in a sheet

Cindy Meister

MKhare wrote:
I'm surprised that there is no straightforward call in VSTO for this.
I am trying to get the range of cells that have been selected by the user, i.e. after user has selected a region of cells using the mouse.
This is the closest I came:

Globals.Sheet2.Application.ActiveCell

This only gives me the range object corresponding to the first cell on the top left of selection.
Thanks in advance...

Maneesh

How about Globals.ThisApplication.Selection

According to the Excel Help, this should return what you're looking for

"Returns the selected object in the active window, for an Application object, and a specified window, for a Windows object."

And a quick test shows it works: Application.Selection.Address returns (for example) $D$8EmbarrassedE$9