|
-
May 11th, 2007, 08:17 AM
#1
Thread Starter
Addicted Member
[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...
Last edited by robbie; May 11th, 2007 at 10:54 AM.
-
May 11th, 2007, 08:37 AM
#2
Addicted Member
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"
IDE: Visual Studio 2008/2010 - C# | VB.Net
-
May 11th, 2007, 09:16 AM
#3
Thread Starter
Addicted Member
Re: Reading Cells in Excel Using VB.NET
That seems to work. Thanks.
-
May 11th, 2007, 02:05 PM
#4
Addicted Member
Re: [RESOLVED] Reading Cells in Excel Using VB.NET
IDE: Visual Studio 2008/2010 - C# | VB.Net
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|