View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
farmer[_2_] farmer[_2_] is offline
external usenet poster
 
Posts: 11
Default How to select other sheets using ADO

Hi,



I use the folowing code to get information from a closed workbook with
ADO. It automatically selects the first sheet.

How do I get it to select other sheets? e.g. sheet2


sub test()

Dim dbConnection As ADODB.Connection, rs As ADODB.Recordset
Dim dbConnectionString As String
Dim i As Integer

dbConnectionString = "DRIVER={Microsoft Excel Driver (*.xls)};" &
"ReadOnly=1;DBQ=E:\AdoVBA\99budget.xls"
Set dbConnection = New ADODB.Connection

dbConnection.Open dbConnectionString ' open the database connection

Set rs = dbConnection.Execute("[" & "a:a" & "]")

Do While Not rs.EOF
UserForm1.ListBox1.AddItem rs.Fields.Item(i)
rs.MoveNext
Loop

rs.Close
dbConnection.Close
Set rs = Nothing
Set dbConnection = Nothing

End sub


Help appreciated,

Farmer