|
一般来说,如果绑定了数据源,直接将数据源转换为一个查询,再导出就好了。
- Private Sub Command4_Click()
- Dim qry As DAO.QueryDef
- Dim strSQL As String
- strSQL = Me.List0.RowSource
- '创建一个查询
- Set qry = CurrentDb.CreateQueryDef("qry1", strSQL)
- DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "qry1", CurrentProject.Path & "\list0.xlsx", True
- '导出后再删除这个查询
- CurrentDb.QueryDefs.Delete "qry1"
- End Sub
复制代码 如果没绑定数据源,则麻烦一些,需要创建Excel文件再写入:
- Private Sub Command5_Click()
- Dim exl As New Excel.Application
- Dim wk As Workbook
- Dim ws As Worksheet
- Dim strSource As String
- Dim i As Long
- Dim strData() As String
- Set wk = exl.Workbooks.Add
- Set ws = wk.ActiveSheet
- strSource = Me.List2.RowSource
- strData = Split(strSource, ";")
- For i = 0 To UBound(strData)
- ws.Cells(i + 1, 1) = strData(i)
- Next
- wk.SaveAs CurrentProject.Path & "\list1.xlsx"
- wk.Close
- exl.Quit
- End Sub
复制代码 本来打算在你的例子上做的,结果似乎引用了别的外部数据,所以重新写了一个例子,供参考(2007-2016版本)。如果没有对应的版本,请自行参考上面的代码。
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|