Help with script to query spreadsheet (Full Version)

All Forums >> [Scripting Technologies] >> VB Script



Message


ggreen681 -> Help with script to query spreadsheet (4/29/2008 2:46:50 PM)

The script is supposed to read the values of the Excel spreadsheet and list the results in the command window however it just hangs.  It never returns any data.

I am testing the script on XP Pro SP2 and the spreadsheet is Excel 2003

If it matters any here are the column headings in the script
Server, OS, Domain, GroupName, EnvName, FileName, FilePath, FileVersion

On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
   "Data Source=C:\Temp\TestBook.xls;" & _
       "Extended Properties=""Excel 8.0;HDR=Yes;"";"
objRecordset.Open "Select * FROM [Sheet1$] Where Server = Server01", _
   objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF
   Wscript.Echo objRecordset.Fields.Item("Server"), _
       objRecordset.Fields.Item("OS"), _
       objRecordset.Fields.Item("Domain"), _
       objRecordset.Fields.Item("GroupName"), _
       objRecordset.Fields.Item("EnvName"), _
       objRecordset.Fields.Item("FileName"), _
       objRecordset.Fields.Item("FilePath"), _
       objRecordset.Fields.Item("FileVersion")
   objRecordset.MoveNext
Loop




akaplan -> RE: Help with script to query spreadsheet (4/30/2008 8:05:09 AM)

The criteria should be in single quotes:
"Select * FROM [Sheet1$] Where Server = 'Server01'"

Alan




ggreen681 -> RE: Help with script to query spreadsheet (4/30/2008 8:21:51 AM)

Perfect.... that took care of it

Thanks




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.34375