|
|
MS Excel - Экспорт данных двух запросов в два разных листа
Private Sub cmdTest01_Click()
Dim exApp As Object, rs As Object, qdf As DAO.QueryDef
Dim i%
Dim objWbk As Object
Dim objWsh As Object
Set exApp = CreateObject("Excel.application")
Set objWbk = exApp.Workbooks.Add
exApp.Visible = True
Set objWsh = objWbk.Worksheets(1)
Set qdf = CurrentDb.QueryDefs("Query_1")
Set rs = qdf.OpenRecordset
For i = 0 To rs.Fields.Count - 1
objWsh.cells(1, i + 1) = rs.Fields(i).Name
Next
objWsh.Range("A2").CopyFromRecordset rs
Set objWsh = objWbk.Worksheets(2)
Set qdf = CurrentDb.QueryDefs("Query_2")
Set rs = qdf.OpenRecordset
For i = 0 To rs.Fields.Count - 1
objWsh.cells(1, i + 1) = rs.Fields(i).Name
Next
objWsh.Range("A2").CopyFromRecordset rs
Set objWsh = Nothing
Set objWbk = Nothing
Set exApp = Nothing
Set rs = Nothing
End Sub
|
|