reading Excel data via vbscript & ado
- From: sumGirl <emebohw@xxxxxxxxxxxx>
- Date: Fri, 17 Aug 2007 11:28:38 -0700
Hey all. I have worked out how to read a single excel cell with a
script and ado, but I cant figure out how to read multiple cells
without opening and closing the ado recordset multiple times. Can
someone help? I know I dont have to use ado to read data from excel,
but I specifically want to do it that way. Heres my code so far, and
all this does is read a single cell and display the value in a message
box...I will do other stuff with those values once I figure out how to
do multiple cells:
'----------------------------------------------------------------------------
On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic= 3
Const adCmdText= &H0001
Set objConnection= CreateObject("ADODB.Connection")
Set objRecordSet= CreateObject("ADODB.Recordset")
my_Path= "\\server1\spreadsheets\"
my_File= "data.xls"
Target_file= my_Path & my_File
objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=" & Target_file & ";Extended Properties=""Excel
8.0;HDR=No;"";"
objRecordset.Open "Select * from [sheet1$B14:C14]",objConnection,
adOpenStatic, adLockOptimistic, adCmdText
Do While Not (objRecordset.EOF)
msgbox OME_File & " Description:" & vbCRLF &
objRecordset.Fields(0).Value
objRecordset.MoveNext
Loop
objRecordset.Close
objConnection.Close
'----------------------------------------------------------------------------
.
- Follow-Ups:
- Prev by Date: Re: Set statement WMI null / empty? error checking on object?
- Next by Date: Change Excel Setting at Logon
- Previous by thread: Re: creating a 'please wait' message
- Next by thread: Re: reading Excel data via vbscript & ado
- Index(es):
Relevant Pages
|