Dim excelapp As Excel.Application
Dim excelwbk As Excel.Workbook
Dim excelwst As Excel.Worksheet
Set excelapp = New Excel.Application
Set excelwbk = excelapp.Workbooks.Add
Set excelwst = excelwbk.Worksheets.Add
定义个记录集rstfld,利用循环导出
For i = 1 To rstfld.Fields.Count
excelwst.Cells(1, i) = rstfld.Fields(i - 1).Name
Next
Sub ExportField(strTableName As String)
Dim myxl As Object
Dim rs As New ADODB.Recordset
Dim n As Integer
rs.Open "select top 1 * from " & strTableName, CurrentProject.Connection
Set myxl = CreateObject("excel.application")
myxl.Visible = True
myxl.workbooks.Add
With myxl.activeworkbook.activesheet
For n = 1 To rs.Fields.Count
.cells(, n) = rs.Fields(n - 1).Name
Next
End With
End Sub
Sub test()
Call ExportField("workbom")
End Sub
Sub ExportField(strTableName As String,strPath as string)
Dim myxl As Object
Dim rs As New ADODB.Recordset
Dim n As Integer
rs.Open "select top 1 * from " & strTableName, CurrentProject.Connection
Set myxl = CreateObject("excel.application")
myxl.Visible = True
myxl.workbooks.Add
With myxl.activeworkbook.activesheet
For n = 1 To rs.Fields.Count
.cells(, n) = rs.Fields(n - 1).Name
Next
End With
myxl.activeworkbook.saveas strpath & "11.xls"
End Sub
Sub test()
Call ExportField("workbom","c:\huangyz\")
End Sub