求VBA高手帮忙,想在Excel 宏A运行完成后自动另存为整个workbook,另存文件名为当时的

2024-11-09 09:28:51
推荐回答(4个)
回答(1):

你试试在“workbook"的 Private Sub Workbook_BeforeClose(Cancel As Boolean) 中加入如下句子:
myNowTime = Format(Now, "yymmdd" &"-" & "hhmmss")
ActiveWorkbook.SaveAs Filename:=currPath & myNowTime &".xls", AddToMru:=False ‘(”currPath“为你的路径及文件名称)

回答(2):

excel自动另存需要编写宏函数。
可以在ThisWorkBook对象中输入代码完成,
代码如下:
Private Sub Workbook_BeforeClose(Cancel As Boolean) ActiveWorkbook.SaveAs Filename:="C:\aaa.xls", _ FileFormat:=xlNormal, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False End Sub
其中C:\aaa.xls就是所备份的文件的路径。

回答(3):

ActiveWorkbook.SaveAs Filename:= _
ThisWorkbook.Path & "\" & Format(Date, "yyyy-MM-dd hh:mm:ss") ,FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False

回答(4):

例子语句:
ActiveWorkbook.SaveAs Format(Now(), "yyyymmdd")