如何导出带有变量的文件(在宏中)?
How can I export file with variable (in macro)?
我想以 xlsx 格式导出我的文件。我可以使用 'ExportWithFormatting' 来做到这一点(见这里)。
但是,我想用“File-XXXX”命名我的文件,其中 XXXX 是从我的表单中检索到的值。
我尝试了几件事都失败了,比如:
Picture
你知道怎么做吗?
谢谢
嗨,最好是在 VBA 中编程。
这是一个如何做的例子:
Public Function ExportExcelFile(ByVal strFilePath, strFileName As String) As Boolean
'Example : ? ExportExcelFile("C\MyDocuments\","TestFileName.xlsx")
Dim strQueryName As String
Dim strFilePathFull As String
Call DoCmd.Hourglass(True)
strFilePathFull = strFilePath & strFileName
strQueryName = "qselPriceListExport"
Call DoCmd.OutputTo(acOutputQuery, strQueryName, acFormatXLSX, strFilePathFull, Autostart:=False)
ExportExcelFile = True
Call DoCmd.Hourglass(False)
End Function
要实现这一点,例如在表单上,您可以转到按钮,转到事件,然后 select 单击然后 select 最底部的选项,之后 VBA IDE将打开。
您可以在此处粘贴以下代码:
Private Sub btnYourButtonNameHere_Click()
call ExportExcelFile("C\MyDocuments\","TestFileName.xlsx")
End Sub
我想以 xlsx 格式导出我的文件。我可以使用 'ExportWithFormatting' 来做到这一点(见这里)。 但是,我想用“File-XXXX”命名我的文件,其中 XXXX 是从我的表单中检索到的值。
我尝试了几件事都失败了,比如: Picture
你知道怎么做吗? 谢谢
嗨,最好是在 VBA 中编程。 这是一个如何做的例子:
Public Function ExportExcelFile(ByVal strFilePath, strFileName As String) As Boolean
'Example : ? ExportExcelFile("C\MyDocuments\","TestFileName.xlsx")
Dim strQueryName As String
Dim strFilePathFull As String
Call DoCmd.Hourglass(True)
strFilePathFull = strFilePath & strFileName
strQueryName = "qselPriceListExport"
Call DoCmd.OutputTo(acOutputQuery, strQueryName, acFormatXLSX, strFilePathFull, Autostart:=False)
ExportExcelFile = True
Call DoCmd.Hourglass(False)
End Function
要实现这一点,例如在表单上,您可以转到按钮,转到事件,然后 select 单击然后 select 最底部的选项,之后 VBA IDE将打开。 您可以在此处粘贴以下代码:
Private Sub btnYourButtonNameHere_Click()
call ExportExcelFile("C\MyDocuments\","TestFileName.xlsx")
End Sub