【发布时间】:2020-07-13 20:37:58
【问题描述】:
我目前正在使用 TransferSpreadsheet 将 Access 2013 中的表格导出到 Excel 文件。我设置了默认文件名和位置。它工作正常,除了当用户更改他们想要将文件保存为“另存为”对话框中的名称时,不会使用该名称保存。有没有办法获取用户在“另存为”对话框中输入的文件名,并将该文件名保存在他们选择的位置?
这是我现在正在做的事情:
Dim strTableName As String
Dim strBasePath As String
Dim strFullPath As String
Dim strFileName As String
Dim dlgSaveAs As Object
Const msoFileDialogSaveAs = 2
With CodeContextObject
strTableName = "New_Rules"
strBasePath = "C:\Users\" & Environ("USERNAME") & "\Documents\"
strFileName = "New_Account_Rules_" & Format(Date, "yyyy-mm-dd")
strFullPath = strBasePath & strFileName & ".xls"
' Display the Save As dialog with a default name and path
Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)
With dlgSaveAs
.InitialFileName = strFullPath
If dlgSaveAs.Show Then
' Do the export
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "New_Rules", strFullPath, True
End If
End With
提前致谢。
【问题讨论】: