Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Const mydelay As Integer = 10
- Public Const mycount As Integer = 3
- Public Const myfolder As String = "\autobackup\"
- Public Sub callmelater()
- For Each mybook In Workbooks
- Call savethisworkbook(mybook)
- Next
- Application.OnTime Now + TimeSerial(0, 0, mydelay), "callmelater"
- End Sub
- Private Sub savethisworkbook(mybook)
- If mybook.Path = vbNullString Then Exit Sub
- On Error Resume Next
- MkDir mybook.Path & myfolder
- On Error GoTo 0
- myfilename = Left(mybook.Name, (InStrRev(mybook.Name, ".") - 1))
- mybook.SaveCopyAs mybook.Path & myfolder & myfilename & "_" & Format(Now, "YYMMDD_hhmmss") & ".xls"
- With Application.FileSearch
- .LookIn = mybook.Path & myfolder
- .fileName = myfilename & "_??????_??????"
- .FileType = msoFileTypeExcelWorkbooks
- .Execute SortBy:=msoSortByLastModified
- If .FoundFiles.Count > mycount Then Kill .FoundFiles.Item(1)
- End With
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement