最近,我有机会想使用FileDialog将查询的结果从Access导出到Excel。 我发现对其进行研究后发现,关于SaveAs是否可以在Access中使用并且找不到简单的例程存在很多困惑。 我做了一些实验,并提出了以下效果很好的方法。
尽管我使用此例程导出到Excel,但从理论上讲,它可以与DoCmd.Output支持的任何格式一起使用,或者实际上可以与任何输出文件的语句一起使用。
Private Sub cmdSendtoExcel_Click()
Dim fd As FileDialog
Dim Title As String
Dim vrtSelectedItem As Variant
Set fd = Application.FileDialog(msoFileDialogSaveAs)
With fd
.AllowMultiSelect = False
.Title = "Save File"
.InitialFileName = "Name Of Report " & Format(Now(), "ddmmyyyyhhnn") & ".xls"
If .Show = True Then
For Each vrtSelectedItem In .SelectedItems
DoCmd.OutputTo acOutputQuery, "query or table name", acFormatXLS, vrtSelectedItem
Next vrtSelectedItem
Else
MsgBox "No file was selected"
End If
End With
End Sub
如果有人知道此例程有任何改进或增强,请随时提供建议。
玛丽
From: https://bytes.com/topic/access/insights/876982-using-msofiledialogsaveas-ms-access