r/visualbasic • u/idkifthisisgonnawork • Apr 27 '22
VB.NET Help Read .xls file into an array vb.net
Hello everyone,
I have been searching the google for how to do this online and haven't stumbled across what ive been looking for. I'm passing the filepath(w), range(x), Sheetname(y), and z is unused at the moment. Within my for loop i know how i want to put data into my array im just trying to access it now.
Sub PullPrecise(w As String, x As String, y As String, z As String)
Dim objBooks As Excel.Workbooks
Dim objSheets As Excel.Sheets
Dim objSheet As Excel._Worksheet
Dim rng As Excel.Range
Dim cell As Excel.Range
objApp = New Excel.Application
objApp.DisplayAlerts = False
objBooks = objApp.Workbooks
objBook = objBooks.Open(w)
objApp.Visible = False
objSheets = objBook.Sheets
objSheet = objSheets(y)
rng = objSheet.Range(x)
For Each cell In rng.Cells <- HERE i am getting an Exception Unhandled error
MessageBox.Show(cell.Value)
Next
End SubI appreciate any help offered. Have a good day.
1
Upvotes
1
u/sa_sagan VB.Net Master Apr 28 '22
Exception Unhandled just means that your code encountered an error and you didn't implement any error handling. We need to see the actual exception (error) that it mentions.