What I am trying to do is enter an Excel Spreadsheet into arrays for each Column.
I am getting an error with my try..catch:
Overload resolution failed because no Public '<>' can be called with these arguments:
'Public Shared Operator <>(a As String, b As String) As Boolean':
Argument matching parameter 'a' cannot convert from '__ComObject' to 'String'.
Visual Basic does not equate a string and an Excel cell with just a ".ToString".
I am getting an error with my try..catch:
Quote:
Overload resolution failed because no Public '<>' can be called with these arguments:
'Public Shared Operator <>(a As String, b As String) As Boolean':
Argument matching parameter 'a' cannot convert from '__ComObject' to 'String'.
Code:
Sub ExceltoArray()
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
xlApp = GetObject("", "Excel.Application")
xlBook = xlApp.Workbooks.Open("C:\mypath\myBook.xlsm")
xlSheet = xlBook.Worksheets("2013")
xlSheet.Activate()
Try
With xlSheet
k = 1
Do While .Cells(k + 4, 1) <> ""
col1(k) = .Range("A" & k + 4).ToString
col2(k) = .Range("B" & k + 4).ToString
col3(k) = .Range("C" & k + 4).ToString
col4(k) = .Range("D" & k + 4).ToString
col5(k) = .Range("E" & k + 4).ToString
k = k + 1
Loop
End With
Catch ex As Exception
TextBox1.Text = ex.Message
End Try
xlBook.Close()
xlApp.Quit()
xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing
End Sub