我遇到过类似的问题,最终用一些 VBA 代码制作了一个电子表格,为我查询并填充了电子表格。我的任务是导出一系列表格,每个表格都在不同的工作表上,但任何标志都可以用来切换到新工作表。无论如何,如果您想查看代码,请告诉我。这是一个可以帮助你的块。只需将 TableSQL 字符串更改为您选择的任何内容。返回的每条记录将作为一行插入工作表中。然后,根据您决定的任何标志,您可以创建并移动到下一张表。如果您需要更多信息,请告诉我(因为这个特定的例子并不是您在做什么)
Private Sub getMyRows(inSchema As String, InTable As String)
Dim RS As Object
Dim TableSQL As String
Dim DataType As String
Dim DataLength As String
Dim DataPrecision As String
Dim DataScale As String
Dim ColCount As Integer
Dim WS As Worksheet
' create a sheet with the current table as name
Worksheets.Add().Name = InTable
Set RS = CreateObject("ADODB.recordset")
TableSQL = "Select * from " & inSchema & "." & InTable
' grab the data
RS.Open TableSQL, conn, adOpenStatic
For ColCount = 0 To RS.Fields.Count - 1
' set column headings to match table
ActiveSheet.Cells(1, ColCount + 1).Value = RS.Fields(ColCount).Name
Next
' copy table data to sheet
With Worksheets(InTable).Range("A2")
.CopyFromRecordset RS
End With
RS.Close
End Sub