First, I'm brand new to visual basic. I used to program quite a bit in Java, but it's been a few years. I recently downloaded and installed Microsoft Visual Basic 2008 Express Edition and have just started programming. At any rate, I'm trying to learn my way around visual basic by creating a program to read and display some data from an excel spread sheet into a simple form. Eventually I hope to use the data in the excel spreadsheet in my program to do some data analysis in Visual Basic. For now, I'm just trying to read and display one cell of data from the excel spreadsheet. I've looked at a few PAQ and was trying to get the following question to work.
http://www.experts-exchange.com/Programming/Misc/Q_20451935.html?sfQueryTermInfo=1+basic+excel+file+read+visualI followed the instruction in the PAQ, but get the following error (Reference to a non-shared member requires an object reference). The line of code that is causing the problem is with the Excel.Workbooks.Open underlined.
objWorkbook = Excel.Workbooks.Open("c:\g
oog.xls")
Again, I'm very new to Visual Basic, but I noticed that the code from the PAQ had a Set in front of that line. Visual Basic 2008 Express Edition would not allow me to type in Set w/ out automatically making it SetAttr. I'm not sure if the code written in the PAQ was from an older version of VB and maybe they got rid of the Set in the version I'm using? I just thought I'd mention.
Any help would be greatly appreciated. If you all have any advice on what would be the best way for me to work with the data in the Excel spreadsheet, that would be great. I'm trying to figure out if it would be easier to grab the data straight from the spreadsheet or if it is possible to import the entire spreadsheet into some sort of data object in VB and work with that? I would appreciate any guidance. Thanks. I'm attaching my code below as well.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim objWorkbook As Excel.Workbook
Dim ObjWorksheet As Excel.Worksheet
Dim objCell As Object
Dim sData As String
Dim iRow As Long
Dim iCol As Long
objWorkbook = Excel.Workbooks.Open("c:\g
oog.xls")
ObjWorksheet = objWorkbook.Worksheets(1)
sData = ObjWorksheet.Cells(1, 1).value
TextBox4.Text = sData
End Sub
Start Free Trial