Example 1: VBScript to read the data from an Excel sheet using ADODB object (Active Data Objects Data Base)
kw.vbs
Option Explicit
Dim objCon, objRecordSet

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

objCon.Open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ=D:\VBScript\Trial.xls;Readonly=True"
objRecordSet.Open "SELECT * FROM [Sheet1$]",objCon
Msgbox objRecordSet.GetString
Set objRecordSet = Nothing
Set objCon = Nothing
Output

Example 2: VBScript to read the data from an Excel sheet using ADODB object
kw.vbs
Dim objCon, objRecordSet, strExlFile
Set objCon = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
strExlFile = "D:\VBScript\Trial.xls"
objCon.Open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ="&strExlFile&";Readonly=True"

Set result = objCon.Execute("Select * from [Sheet1$]")
colCount = result.Fields.Count
MsgBox "Number of column: " & colCount & vbcrlf & result.GetString 

Set objRecordSet = Nothing
objCon.Close
Set objCon = Nothing
Output

What Next?
Ranorex
Advertisement