Forum Discussion
rraghvani
3 years agoChampion Level 3
Here are two examples that work on Windows 10 with the appropriate ODBC drivers.
Sub TestProc()
Set AConn = ADO.CreateConnection
AConn.ConnectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; DBQ=C:\Temp\Book1.xlsx"
AConn.Open
Set Cmd = ADO.CreateCommand
Cmd.ActiveConnection = AConn
Cmd.CommandText = "SELECT * FROM [Sheet1$]"
Cmd.CommandType = adCmdText
Set RecSet = Cmd.Execute
RecSet.MoveFirst
While Not RecSet.EOF
Log.Message RecSet("A").Value
RecSet.MoveNext
Wend
AConn.Close
End Sub
and
Sub TestProc1()
Set Conn = CreateObject("ADODB.Connection")
Conn.ConnectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; DBQ=C:\Temp\Book1.xlsx"
Conn.Open
Set Rs = CreateObject("ADODB.Recordset")
Rs.Open "[Sheet1$]", Conn, adOpenStatic, adLockReadOnly
Rs.MoveFirst
While Not Rs.EOF
Log.Message Rs.Fields.Item("A").Value
Rs.MoveNext
WEnd
Rs.Close
Conn.Close
End Sub
Related Content
- 5 years ago
Recent Discussions
- 2 days ago
- 2 days ago
- 5 days ago