用EXCEL写一个宏.每天自动以日期时间为文件名保存怎么写?

来源:百度知道 编辑:UC知道 时间:2024/05/28 05:44:36
用EXCEL写一个宏.每天自动以日期时间为文件名保存怎么写?
我没写过宏。。也不会写宏,请大虾们直接给一个好吗?

自己录制一定行代码就ok了

Sub 按钮1_单击()
Application.ScreenUpdating = False
Application.EnableEvents = False

With Application.FileSearch
.LookIn = ThisWorkbook.Path
.Filename = Format(Date, "yyyymmdd") & "*.xls"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then
ActiveSheet.Copy
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & Format(Date, "yyyymmdd") & Format(.FoundFiles.Count + 1, "-000") & ".XLS"
Else
ActiveSheet.Copy
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & Format(Date, "yyyymmdd") & "-001.XLS"
End If
If MsgBox("是否关闭已经生成的文件?", vbYesNo, "请选择!") = vbYes Then ActiveWorkbook.Close
End With
Application.ScreenUpdating = True
Applicatio