Question Excel Interop. Detect when user has not made a selection

robertb_NZ

Well-known member
Joined
May 11, 2010
Messages
146
Location
Auckland, New Zealand
Programming Experience
10+
I am writing a VB.NET program that opens a spreadsheet, and then gets various information from it based on user actions. For example, to get the first data row, the program uses
Dim xlApp As Excel.Application = New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
xlWorkBook = xlApp.Workbooks.Open(txtFilename.Text)
xlWorkSheet = xlWorkBook.Worksheets(1) 'Get first (or only) spreadsheet
xlApp.Visible = True​
Dialog asking the user to select the first data row. then
FirstDataRow = xlApp.ActiveCell.Row​

This all works correctly when the user selects a row, but I would like to know if they simply click the [Next] button without doing so. How do I do this? I'd like to set the value of ActiveCell so that it returns Nothing until a selection is made, but it's a read-only property.
Thank you, Robert.
 
Worksheet has a SelectionChange event that you can handle in your app.
 

Latest posts

Back
Top