Results 1 to 2 of 2

Thread: How to Read EXCEL worksheets

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Location
    Karachi
    Posts
    1
    how i know from vb that how much columns and rows in execl has data
    thanks in advance

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    This shows how to connect to an Excel file via ADO
    You should be able to use the fields.count property and the recordcount property to determine how many rows/columns you have in your excel sheet

    Code:
    'uses ado 2.1 or higher
    
        Dim cn As New Connection
        Dim rs As New Recordset
        
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Test.xls;Extended Properties=Excel 8.0;"
        
        'excel sheet name here
        'must enclose in brackets, sheet name followed by a dollar sign
        rs.Open "Select * from [Sheet1$]", cn, adOpenKeyset, adLockOptimistic
        
        'see value
        MsgBox rs.Fields(0).Value
        
        'change it
        rs.Fields(0).Value = rs.Fields(0).Value & "3"
        
        'update
        rs.Update
        
        'verify change
        MsgBox rs.Fields(0).Value

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