MR Campbell
Board Regular
- Joined
- Aug 2, 2002
- Messages
- 113
At present I am attempting a rather simple task ... to read a cell from an existing sheet from an existing Excel file using Visual Basic (Visual Studio 2010). I am unable to do this as I am getting an error message at the indicated line. I have already added a reference to Excel 14.0 (Excel 2010) within my VB project. Any ideas ?
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim FirstName, Surname As String
'file path and name for the Excel file
Dim FileNamePath As String = "C:\Users\MRC\Desktop\MRC Files\Visual Basic Files\SwimManager 2014\CurrentSeasonDATA\SquadData.xls"
Dim XL = CreateObject("Excel.Application") 'reference Excel as the application
XL.Visible = False 'make Excel application invisible
XL.Workbooks.Open(FileNamePath) 'open the designated workbook file
FirstName = XL.Worksheets("DOB").Cells(6, 3).Value 'read the first name <======== getting the ERROR ON THIS LINE
Surname = XL.Worksheets("DOB").Cells(6, 4).Value 'read the surname
'Write the name to a textbox
TextBox2.Text = FirstName & " " & Surname
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim FirstName, Surname As String
'file path and name for the Excel file
Dim FileNamePath As String = "C:\Users\MRC\Desktop\MRC Files\Visual Basic Files\SwimManager 2014\CurrentSeasonDATA\SquadData.xls"
Dim XL = CreateObject("Excel.Application") 'reference Excel as the application
XL.Visible = False 'make Excel application invisible
XL.Workbooks.Open(FileNamePath) 'open the designated workbook file
FirstName = XL.Worksheets("DOB").Cells(6, 3).Value 'read the first name <======== getting the ERROR ON THIS LINE
Surname = XL.Worksheets("DOB").Cells(6, 4).Value 'read the surname
'Write the name to a textbox
TextBox2.Text = FirstName & " " & Surname
End Sub