PDA

Click to See Complete Forum and Search --> : How to Read EXCEL worksheets


farheen
Jan 10th, 2001, 01:10 AM
how i know from vb that how much columns and rows in execl has data
thanks in advance

Clunietp
Jan 10th, 2001, 09:53 AM
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


'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