Dim cn 'As ADODB.Connection Dim rsExcel 'As ADODB.Recordset Dim intField, intFields 'As Integer Dim strTable 'As String Dim dtDateModified 'As Date Const adUseClient = 3 'ADODB.CursorLocationEnum Const adUseServer = 2 'ADODB.CursorLocationEnum Const adLockBatchOptimistic = 4 'ADODB.LockTypeEnum Const adLockOptimistic = 3 'ADODB.LockTypeEnum Const adLockPessimistic = 2 'ADODB.LockTypeEnum Const adLockReadOnly = 1 'ADODB.LockTypeEnum Const adSchemaColumns = 4 'ADODB.SchemaEnum Const adSchemaStatistics = 19 'ADODB.SchemaEnum Const adSchemaTables = 20 'ADODB.SchemaEnum Const adOpenDynamic = 2 'ADODB.CursorTypeEnum Const adOpenForwardOnly = 0 'ADODB.CursorTypeEnum Const adOpenKeyset = 1 'ADODB.CursorTypeEnum Const adOpenStatic = 3 'ADODB.CursorTypeEnum Set cn = CreateObject("ADODB.Connection") cn.Provider = "Microsoft.Jet.OLEDB.4.0" cn.Properties("Data Source") = "D:\MYDOCU~1\PROJECTS\ADO\ADO.XLS" cn.Properties("Extended Properties").Value = "Excel 8.0;" _ & "HDR=NO;" _ & "MAXSCANROWS=16;" _ & "IMEX=1;" cn.Open 'Find the worksheet name strTable = "" On Error Resume Next 'Sometimes you can't see the columns Err.Clear Set rsExcel = cn.OpenSchema(adSchemaColumns) If Err.Number = 0 Then 'Find the worksheet because it has the most used columns intField = 0 Do While Not rsExcel.EOF If rsExcel.Fields("ORDINAL_POSITION") > intField Then If InStr(rsExcel.Fields("TABLE_NAME").Value, "$Print_Area") = 0 Then strTable = rsExcel.Fields("TABLE_NAME").Value intField = rsExcel.Fields("ORDINAL_POSITION") End If End If rsExcel.MoveNext Loop Else 'Hope the worksheet is the only one! Set rsExcel = cn.OpenSchema(adSchemaTables) rsExcel.MoveFirst Do While Not rsExcel.EOF If Instr(rsExcel.Fields("TABLE_NAME"), "Print_") = 0 Then strTable = rsExcel.Fields("TABLE_NAME") Exit Do End If rsExcel.MoveNext Loop End If rsExcel.Close Set rsExcel = Nothing 'Get the edited date of the spreadsheet Set rsExcel = cn.OpenSchema(adSchemaTables) rsExcel.MoveFirst Do While Not rsExcel.EOF If rsExcel.Fields("TABLE_NAME") = strTable Then dtDateModified = Cdate(rsExcel.Fields("DATE_MODIFIED")) Exit Do End If rsExcel.MoveNext Loop rsExcel.Close Set rsExcel = Nothing 'Open the worksheet Set rsExcel = CreateObject("ADODB.Recordset") rsExcel.ActiveConnection = cn rsExcel.CursorType = adOpenStatic rsExcel.LockType = adLockReadOnly rsExcel.Source = "SELECT * FROM [" & strTable & "]" rsExcel.Open 'Read the worksheet headers intFields = rsExcel.Fields.Count Wscript.Echo "" For intField = 0 To intFields - 1 Wscript.Echo "" Next Wscript.Echo "" 'Read the worksheet body rsExcel.MoveFirst Do While Not rsExcel.EOF Wscript.Echo "" For intField = 0 To intFields - 1 Wscript.Echo "" Next Wscript.Echo "" rsExcel.MoveNext Loop Wscript.Echo "
" & rsExcel.Fields.Item(intField).Name & "
" & rsExcel.Fields.Item(intField).Value & "
" 'ADO Cleanup rsExcel.Close Set rsExcel = Nothing cn.Close Set cn = Nothing