gpt4 book ai didi

excel - VBA 代码另存为 .XLSM

转载 作者:行者123 更新时间:2023-12-04 12:18:42 24 4
gpt4 key购买 nike

需要帮助才能添加命令以另存为 .xlsm:-

Private Sub cmdSaveForm1_Click()
Dim strFolder As String
Dim i As Long

'Find the position of the period in the file name
i = InStr(ActiveWorkbook.Name, ".")

'Create a default file name by concatenating the file name without the extention _
plus the current date and time, and plus the xlsm extention
Filename = Left(ActiveWorkbook.Name, i - 1) & "_" & Format(Now, "yyyy-mm-dd_hh mm") & ".xlsm"

'Open Save As dialog to a default folder with default file name
With Application.FileDialog(msoFileDialogSaveAs)
.AllowMultiSelect = False
.InitialFileName = "P:\EU Funds Management - Treasury\TRS3_Abstract of Payments\TRS3_Authorisation_L1\" & Filename
.InitialView = msoFileDialogViewDetails
If .Show = -1 Then strFolder = .SelectedItems(1) Else Exit Sub
.Execute
End With
End Sub

最佳答案

将工作簿另存为 .xlsm您需要以下文件格式

Excel 2007-2010 Macro-Enabled Workbook (.xlsm) - 52 - xlOpenXMLWorkbookMacroEnabled



要将文件保存为选定的格式,您需要在保存时指定适当的格式。这可以通过添加 FileFormat:= 来完成到您的保存操作。
ThisWorkbook.SaveAs Filename:=Path & Filename, FileFormat:=xlOpenXMLWorkbookMacroEnabled

下面添加了保存操作和 FileFormat到你的代码。
Private Sub cmdSaveForm1_Click()
Dim strFolder As String
Dim i As Long

'Find the position of the period in the file name
i = InStr(ActiveWorkbook.Name, ".")

'Create a default file name by concatenating the file name without the extention _
plus the current date and time, and plus the xlsm extention
Filename = Left(ActiveWorkbook.Name, i - 1) & "_" & Format(Now, "yyyy-mm-dd_hh mm") & ".xlsm"

'Open Save As dialog to a default folder with default file name
With Application.FileDialog(msoFileDialogSaveAs)
.AllowMultiSelect = False
.InitialFileName = "P:\EU Funds Management - Treasury\TRS3_Abstract of Payments\TRS3_Authorisation_L1\" & Filename
.InitialView = msoFileDialogViewDetails

If .Show = -1 Then strFolder = .SelectedItems(1) Else Exit Sub

'get selected folder path from FileDialog, but remove filename from FileDialog
folderPath = Left(strFolder, InStrRev(strFolder, "\"))

'Save this workbook in chosen file path & appropriate filename
'File format .xlsm
ThisWorkbook.SaveAs Filename:=folderPath & Filename, FileFormat:=xlOpenXMLWorkbookMacroEnabled
End With
End Sub

关于excel - VBA 代码另存为 .XLSM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48733454/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com