用EXCEL写一个宏.每天自动以日期时间为文件名保存怎么写?
用EXCEL写一个宏.每天自动以日期时间为文件名保存怎么写?我没写过宏。。也不会写宏,请大虾们直接给一个好吗?...
用EXCEL写一个宏.每天自动以日期时间为文件名保存怎么写?
我没写过宏。。也不会写宏,请大虾们直接给一个好吗? 展开
我没写过宏。。也不会写宏,请大虾们直接给一个好吗? 展开
展开全部
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
Application.EnableEvents = True
End Sub
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
Application.EnableEvents = True
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |