|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Private Sub Command17_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim I As Integer
Dim x As Integer
Dim oExcel As Object
Dim oBook As Object
strSQL = "SELECT * FROM 数据Data WHERE 查询条件
If strSQL = "" Then Exit Sub
Set conn = CurrentProject.Connection
rs.Open strSQL, conn, 1, 3
If rs.RecordCount = 0 Then rs.Close: Exit Sub
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Add()
Set xlSheet = oBook.Worksheets(1)
oExcel.Visible = True
For I = 0 To rs.Fields.Count - 1
xlSheet.Cells(1, I + 1).Value = rs.Fields(I).Name
Next
xlSheet.Cells(2, 1).CopyFromRecordset rs
rs.Close
End Sub |
|