[RESOLVED] Reading Cells in Excel Using VB.NET
Back in VB6, all I had to do is create the Excel.Application object, open the workbook and use the cells object. That doesn't seem to work using vb.net.
In vb.net, I'm imported the following namespace:
Code:
Imports Excel = Microsoft.Office.Interop.Excel
Then, I create the object
Code:
Dim oApp As Excel.Application = New Excel.Application
Then, using a with oApp block, I am able to open the workbook
Code:
.Workbooks.Open(strSource, , , , , "dbbfrb")
Then, I try to read a cell value (This is where the exception is thown)
Code:
If CStr(.Cells(X, 1)) = "098" Then
Does anybody know how to read from or write to cells in Excel using vb.net? Obviously, I'm missing a step but I can't seem to find what it is.
Any help on this would be greatly appreciated...
Re: Reading Cells in Excel Using VB.NET
This might help.
Code:
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
oWB = oApp.Workbooks.Open(strSource, , , , , "dbbfrb")
oSheet = oWB.ActiveSheet
oSheet.Cells(1, 1).Value = "Value 1"
oSheet.Cells(1, 2).Value = "Value 2"
Re: Reading Cells in Excel Using VB.NET
That seems to work. Thanks.
Re: [RESOLVED] Reading Cells in Excel Using VB.NET
Glad to hear :thumb:
I'll cite my source,
http://support.microsoft.com/kb/219151/