Results 1 to 4 of 4

Thread: [RESOLVED] Reading Cells in Excel Using VB.NET

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Location
    Milwaukee, Wisconsin, USA
    Posts
    133

    Question [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.

  2. #2
    Addicted Member Isorfir's Avatar
    Join Date
    Feb 2006
    Location
    In Debug Mode
    Posts
    133

    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Location
    Milwaukee, Wisconsin, USA
    Posts
    133

    Re: Reading Cells in Excel Using VB.NET

    That seems to work. Thanks.

  4. #4
    Addicted Member Isorfir's Avatar
    Join Date
    Feb 2006
    Location
    In Debug Mode
    Posts
    133

    Re: [RESOLVED] Reading Cells in Excel Using VB.NET

    Glad to hear

    I'll cite my source,
    http://support.microsoft.com/kb/219151/
    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
  •  



Click Here to Expand Forum to Full Width