Linker IT Software
menubar-top-links menubar-top-rechts
Home Help Search Login
Welcome, Guest. Please Login.
SQL*XL: Database to Excel bridge litLIB: Excel power functions pack ExcelLock: Locking and securing your valuable Excel spreadsheets encOffice: Protect your Excel file easy and safe encOffice: Protect your Excel file easy and safe
Pages: 1
Looping SQL (Read 3464 times)
Gerrit-Jan Linker
YaBB Administrator

Posts: 75
Looping SQL
17.05.09 at 17:13:23
Looping SQL
I'd like to use my query, with a variable in the where clause,
within a loop so that I can send data to several different tabs in the

This can be easily achieved. As an example consider the next code fragment. It assumes that the names of each worksheet is a table name. It loops the worksheets and dumps the contents of the table in each sheet

Dim wks as Worksheet
For each wks in ThisWorkbook
    SQLXL.Sql.setText "select * from " & wks.Name & " to " & wks.Name & "!A1"
    Set SQLXL.Sql.Statements(1).Target = Targets(litExcel)
    With SQLXL.Sql.Statements(1)
       .ShowParametersDlg = False
       .ShowResultsetDlg = False
    End With
Next wks
Back to top

Gerrit-Jan Linker
Linker IT Software
Email WWW Gerrit-Jan Linker   IP Logged
Pages: 1