Workbook_BeforeClose Question

JH

New Member
Joined
Nov 23, 2005
Messages
16
Do any of you Excel gurus see any potential problems with executing code similar to this in order to create backups when closing a workbook?

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Dir("C:\test3.xls") <> "" Then Kill ("C:\test3.xls")
If Dir("C:\test2.xls") <> "" Then Name "C:\test2.xls" As "C:\test3.xls"
If Dir("C:\test1.xls") <> "" Then Name "C:\test1.xls" As "C:\test2.xls"
ActiveWorkbook.SaveAs Filename:="C:\test1.xls", Password:="test"
End Sub

TIA
JH
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

JH

New Member
Joined
Nov 23, 2005
Messages
16
Thanks Brian.
So far it seems to be working well. At first, I was concerned with Window's OS burping from the quick delete/rename process, but I think it may work successfully.

JH
 

Watch MrExcel Video

Forum statistics

Threads
1,119,272
Messages
5,577,133
Members
412,769
Latest member
VK12345
Top