Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Workbook backup before opening?

I am trying to create a backup of a workbook before
opening it for new updates, I think I have the code right
but am not sure where to place this code so that it
executes before the "Current" workbook opens? my code is
as follows;
==
Dim Source, Destination
Source = "C:\Current.xls"
Destination = "C:\Backup\Current_" &Format(Date,"YYMMDD")
& ".xls"
FileCopy Source, Destination
==

Any advice, help will be greatly appreciated.

Thanks,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Workbook backup before opening?

Toothfish,

In the Code for ThisWorkbook:
Private Sub Workbook_Open()
Dim Source, Destination
Source = "C:\Current.xls"
Destination = "C:\Backup\Current_" & Format(Date, "YYMMDD") & ".xls"
FileCopy Source, Destination
End Sub

Or under Auto_Open in a Module

Rob

"toothfish__" wrote in message
...
I am trying to create a backup of a workbook before
opening it for new updates, I think I have the code right
but am not sure where to place this code so that it
executes before the "Current" workbook opens? my code is
as follows;
==
Dim Source, Destination
Source = "C:\Current.xls"
Destination = "C:\Backup\Current_" &Format(Date,"YYMMDD")
& ".xls"
FileCopy Source, Destination
==

Any advice, help will be greatly appreciated.

Thanks,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Workbook backup before opening?

Suggest you use a 4 digit year to make the date less
ambiguous. perhaps something like
dname = "c:\mybackup\B" & Format(Now(), "yyyy_mmdd")


You could use BeforeSave described in
Backup your files, always take backups
Location: http://www.mvps.org/dmcritchie/excel/backup.htm

and in http://www.mvps.org/dmcritchie/excel/events.htm

--
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"toothfish__" wrote in message ...
I am trying to create a backup of a workbook before
opening it for new updates, I think I have the code right
but am not sure where to place this code so that it
executes before the "Current" workbook opens? my code is
as follows;
==
Dim Source, Destination
Source = "C:\Current.xls"
Destination = "C:\Backup\Current_" &Format(Date,"YYMMDD")
& ".xls"
FileCopy Source, Destination
==

Any advice, help will be greatly appreciated.

Thanks,



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Workbook backup before opening?

Is this code in your c:\current.xls workbook?

If yes, then I don't think filecopy will work with an open file.

You may want to look at savecopyas in vba's help:

Option Explicit
Private Sub Workbook_Open()
ThisWorkbook.SaveCopyAs "C:\backup\Current_" _
& Format(Date, "YYMMDD") & ".xls"
End Sub

If you're using the code in a different workbook, then never mind.

toothfish__ wrote:

I am trying to create a backup of a workbook before
opening it for new updates, I think I have the code right
but am not sure where to place this code so that it
executes before the "Current" workbook opens? my code is
as follows;
==
Dim Source, Destination
Source = "C:\Current.xls"
Destination = "C:\Backup\Current_" &Format(Date,"YYMMDD")
& ".xls"
FileCopy Source, Destination
==

Any advice, help will be greatly appreciated.

Thanks,


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Workbook backup before opening?

"Rob van Gelder" wrote in message ...
Toothfish,

In the Code for ThisWorkbook:
Private Sub Workbook_Open()
Dim Source, Destination
Source = "C:\Current.xls"
Destination = "C:\Backup\Current_" & Format(Date, "YYMMDD") & ".xls"
FileCopy Source, Destination
End Sub

Or under Auto_Open in a Module

Rob


thanks Rob,

initially got a "permission denied" error, but modified the sequence
and works fine now.

appreciate your help.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Workbook backup before opening?

"David McRitchie" wrote in message ...
Suggest you use a 4 digit year to make the date less
ambiguous. perhaps something like
dname = "c:\mybackup\B" & Format(Now(), "yyyy_mmdd")


You could use BeforeSave described in
Backup your files, always take backups
Location: http://www.mvps.org/dmcritchie/excel/backup.htm

and in http://www.mvps.org/dmcritchie/excel/events.htm

--
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm


thanks David,

have adapted the date format as you proposed and used a SaveCopyAs,
seems to work fine.

appreciate the links and your help.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Workbook backup before opening?

Dave Peterson wrote in message ...
Is this code in your c:\current.xls workbook?

If yes, then I don't think filecopy will work with an open file.

You may want to look at savecopyas in vba's help:

Option Explicit
Private Sub Workbook_Open()
ThisWorkbook.SaveCopyAs "C:\backup\Current_" _
& Format(Date, "YYMMDD") & ".xls"
End Sub

If you're using the code in a different workbook, then never mind.


thanks Dave,

yes the code was in the c:\current.xls workbook and FileCopy then
prompted a "permission denied" error. So have adapted the SaveCopyAs
and works perfectly now.

appreciate your help.
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Workbook backup before opening?

You're welcome, thanks for the feedback on what you
actually did in your reply to my post, and to others that replied.

Such feedback is very helpful when you get a lot of replies
as to what you choose, and why, if not otherwise clear,
and especially when the person who replies might not know
if he is providing the correct answer or not.

"toothfish__" wrote in message
have adapted the date format as you proposed and used a SaveCopyAs, seems to work fine.

appreciate the links and your help.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
auto save a backup copy of a workbook Ese Excel Discussion (Misc queries) 1 October 13th 08 10:35 AM
Shared Workbook creating Backup when saved? LG Excel Discussion (Misc queries) 1 July 21st 08 10:58 PM
backup copy of a workbook R..VENKATARAMAN Excel Discussion (Misc queries) 0 February 1st 06 12:47 PM
backup copy of a workbook R..VENKATARAMAN Excel Discussion (Misc queries) 0 February 1st 06 12:24 PM
How to make the opening of a workbook conditional upon the opening of another workbook Marcello do Guzman Excel Programming 1 December 16th 03 06:09 AM


All times are GMT +1. The time now is 10:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"