Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone! This must be quite easy, but I have been struggling for a while now (and yes, I googled but could not make sense of what I found).

My procedure receives an excel workbook as input parameter. I need to find the currently selected cell range...

My only line of code so far

VB
xlWorksheet = xlInputWorkBook.ActiveSheet


Does anyone have a clue as how to i retrieve the selected cell range?

My guess is xlWorksheet.Cells.SomePropertyICanNotFind

TIA for your help!

PS: I am not using VBA, but VB.NET to build a standalone application
Posted
Updated 13-Oct-11 10:10am
v2

1 solution

What you are looking for is actually just what you would expect... and that is Selection

http://msdn.microsoft.com/en-us/library/aa196885%28v=office.11%29.aspx[^]

In vb.net it is a property of Application. This is because Excel is single user and therefor can have only one selection at a time.
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.application_properties.aspx[^]

Good luck!
 
Share this answer
 
v2
Comments
iris.frigole 14-Oct-11 11:02am    
Thanks! I think I stubbornly googled "excel worksheet" and "excel workbook" then selection, current range, active range and so on...

The thing is the Selection property "Returns the selected object in the active window." and, yes, even if one application has more than one workbook open it still has only one active window!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900