View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
DS DS is offline
external usenet poster
 
Posts: 117
Default How to backup excel files?

Hi romelsb,

I take it setting the "backup" option in the SaveAs dialog box to
automatically back up your workbook isn't sufficient?

If you use the following, it'll automatically save your workbook in the
current location, and back up your workbook to the specified location on
close. This needs placing in the ThisWorkbook section, rather than in a
module or sheet.

****************
Private Sub Workbook_BeforeClose(Cancel As Boolean)

ThisWorkbook.Save
ThisWorkbook.SaveAs "C:\BackUps\NameIt.xls", Password:="yahoo"

End Sub
****************
You'll obviously need to direct the path above to a valid folder, file name
etc!

WARNING: this will save the workbook on close. If you may want to close
WITHOUT saving, add a yes/no message box to the beginning of the code to
allow the user to exit without saving / backing up. Very useful when you're
doing some development and you make a complete hash of things and just want
to start again from your last save point... as I found out the hard way!!!

HTH
DS





"romelsb" wrote:

Can anybody of good intention, program an excel workbook to provide another
back up file...I had many experience since 1992 wherein after saving and
closing my files and re-open again,,,error will appear and then it is unable
to read....I loss bunch of time using the good functions of excel yet the
program cannot fully protect the users work...I am still hoping that good
VBE tricks may do this ...proofchecksavebackupclose....
--
"Bright minds are blessed to those who share them.."-rsb.