Question

I am working in VB.NET (VS2010) and want to provide a facility enabling the user to choose a file from a list of Excel spreadsheets, which is then opened via VB.NET, visible to the user, and they select a range of cells. I want to capture the range selected. However, the worksheet object does not seem to have a property to allow me to find out what the selected range is. There is a UsedRange property, which tells me all the cells that are in use, but I need just the ones the user has selected. I see plenty of examples of how to select a range programmatically, but not how to retrieve a range selected by the user. In Excel VBA there appears to be a "Selection" object, but I can't find anything comparable in the VB.NET Excel InterOp object model. I don't have any code that I think is useful to post - the rest of what I want to do is working fine using code examples from other SO questions. Is there a way to find the selected range?

Was it helpful?

Solution

Selection is a property of either the Excel Application or Window.

Presumably you have an object reference such as xlApp so you would use xlApp.Selection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top