我正在尝试从下面的代码中导出部分或部分列。
它正在导出从Access到Excel的所有内容。
我对任何建议表示赞赏。
Dim theFilePath As String
reportname = "X"
theFilePath = "C:\Documents and Settings\" & Environ("UserName") & "\Desktop\"
theFilePath = theFilePath & reportname & "_" & Format(Date, "yyyy-mm-dd") & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, reportname, theFilePath, True
MsgBox "The Excel file is Downloaded in your Desktop"
构造一个查询,从您的表/查询中选择所需的列(在代码中命名为X
),并使用TransferSpreadsheet
对象的DoCmd
方法输出查询。
例如,您可以构造一个如下所示的查询,其中YourField1...N
是所需的列,x
是您的数据集(表/查询):
select x.YourField1, x.YourField2, x.YourField3 from x
将此查询保存在MS Access中作为MyQuery
,然后将reportname = "X"
更改为reportname = "MyQuery"