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


Dear all, I have the following code, which saves a backup of the file
being opened. I would appreciate your help on changing it so that it
saves into a directory called \backup in the same file path.

Many thanks for any help !
love Amy xx

Private Sub Workbook_Open()
Dim sStr As String

sStr = Format(Now, "yyyymmdd hh-mm")

Me.SaveAs Filename:=Me.Name & " " & sStr, _
FileFormat:=xlWorkbookNormal
End Sub


--
AmyTaylor
------------------------------------------------------------------------
AmyTaylor's Profile: http://www.excelforum.com/member.php...o&userid=20970
View this thread: http://www.excelforum.com/showthread...hreadid=500532

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default saving backup

Hi Amy,

Try:

'=============
Private Sub Workbook_Open()
Dim sStr As String
Dim sPath As String

sStr = Format(Now, "yyyymmdd hh-mm")
sPath = Me.Path & "\Backup\"

Me.SaveAs Filename:=sPath & Me.Name & " " & sStr, _
FileFormat:=xlWorkbookNormal
End Sub
'<<=============


---
Regards,
Norman


"AmyTaylor" wrote
in message ...

Dear all, I have the following code, which saves a backup of the file
being opened. I would appreciate your help on changing it so that it
saves into a directory called \backup in the same file path.

Many thanks for any help !
love Amy xx

Private Sub Workbook_Open()
Dim sStr As String

sStr = Format(Now, "yyyymmdd hh-mm")

Me.SaveAs Filename:=Me.Name & " " & sStr, _
FileFormat:=xlWorkbookNormal
End Sub


--
AmyTaylor
------------------------------------------------------------------------
AmyTaylor's Profile:
http://www.excelforum.com/member.php...o&userid=20970
View this thread: http://www.excelforum.com/showthread...hreadid=500532



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default saving backup


Thank you very much Norman, can I ask one final question ?

Is it possible to add something, whereby if the folder called \backup
doesnt exist it creates it then saves the backup file to it?
Thank you!!
Amy xx


--
AmyTaylor
------------------------------------------------------------------------
AmyTaylor's Profile: http://www.excelforum.com/member.php...o&userid=20970
View this thread: http://www.excelforum.com/showthread...hreadid=500532

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default saving backup

Dim sFolder As String
On Error Resume Next
sFolder = Dir(Folder, vbDirectory)
If sFolder < "" Then
If (GetAttr(sFolder) And vbDirectory) = vbDirectory Then
'do nothing
Else
MkDir sFolder
End If
End If



--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"AmyTaylor" wrote in
message ...

Thank you very much Norman, can I ask one final question ?

Is it possible to add something, whereby if the folder called \backup
doesnt exist it creates it then saves the backup file to it?
Thank you!!
Amy xx


--
AmyTaylor
------------------------------------------------------------------------
AmyTaylor's Profile:

http://www.excelforum.com/member.php...o&userid=20970
View this thread: http://www.excelforum.com/showthread...hreadid=500532



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default saving backup

Hi Amy,

As an alternative to Bob's suggestion, you could simply create the backup
folder and use an error handler to deal with the possiblie existence.

Try:

'=============
Private Sub Workbook_Open()
Dim sStr As String
Dim sPath As String

sStr = Format(Now, "yyyymmdd hh-mm")
sPath = Me.Path & "\Backup\"

On Error Resume Next
MkDir sPath
On Error GoTo 0

Me.Save Filename:=sPath & Me.Name & " " & sStr, _
FileFormat:=xlWorkbookNormal
End Sub
'<<=============

However, if the intention is that the original file should remain open
(rather than the backup copy), then change:

Me.Save Filename:=sPath & Me.Name & " " & sStr, _

FileFormat:=xlWorkbookNormal

to:

Me.SaveCopyAs Filename:=sPath & Me.Name & " " & sStr

In this way, the original file remains open (and unchanged) whilst a backup
copy is saved to the Backup folder.


---
Regards,
Norman



"AmyTaylor" wrote in
message ...

Thank you very much Norman, can I ask one final question ?

Is it possible to add something, whereby if the folder called \backup
doesnt exist it creates it then saves the backup file to it?
Thank you!!
Amy xx


--
AmyTaylor
------------------------------------------------------------------------
AmyTaylor's Profile:
http://www.excelforum.com/member.php...o&userid=20970
View this thread: http://www.excelforum.com/showthread...hreadid=500532





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default saving backup


Hi Bob & Norman,

your help is sooooo fantastic. Can I ask another question ?
Sometimes the file is opened as read only, in which case I wouldnt want
the file to be be backed up. Is it possible to add something which only
creates a backup if the file is opened as read only ?!!

Thanks both, :)
Love Amy xx


--
AmyTaylor
------------------------------------------------------------------------
AmyTaylor's Profile: http://www.excelforum.com/member.php...o&userid=20970
View this thread: http://www.excelforum.com/showthread...hreadid=500532

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default saving backup

Hi Amy,

Your statement:

Sometimes the file is opened as read only, in which case I wouldnt
want the file to be be backed up.


seems at odds with:

Is it possible to add something which only creates a backup if the
file is opened as read only ?!!


Assuming the first interpretation, try:

'=============
Private Sub Workbook_Open()
Dim sStr As String
Dim sPath As String

If Me.ReadOnly Then Exit Sub '<<==== ADDITION

sStr = Format(Now, "yyyymmdd hh-mm")
sPath = Me.Path & "\Backup\"

On Error Resume Next
MkDir sPath
On Error GoTo 0

Me.Save Filename:=sPath & Me.Name & " " & sStr, _
FileFormat:=xlWorkbookNormal
End Sub
'<<=============

If, however, the second interpretation shoul prevail, change:

If Me.ReadOnly Then Exit Sub
to

If Not Me.ReadOnly Then Exit Sub


---
Regards,
Norman


"AmyTaylor" wrote
in message ...

Hi Bob & Norman,

your help is sooooo fantastic. Can I ask another question ?
Sometimes the file is opened as read only, in which case I wouldnt want
the file to be be backed up. Is it possible to add something which only
creates a backup if the file is opened as read only ?!!

Thanks both, :)
Love Amy xx


--
AmyTaylor
------------------------------------------------------------------------
AmyTaylor's Profile:
http://www.excelforum.com/member.php...o&userid=20970
View this thread: http://www.excelforum.com/showthread...hreadid=500532



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default saving backup


Fantastic, that works perfectly :)
My mistake re the read-only statement, I only want it to backup whe
the file is opened as read-write. Silly me!
Thanks
Amy x

--
AmyTaylo
-----------------------------------------------------------------------
AmyTaylor's Profile: http://www.excelforum.com/member.php...fo&userid=2097
View this thread: http://www.excelforum.com/showthread.php?threadid=50053

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
Excels auto recovery file is saving as a backup, how do i stop tha EPSCoR Setting up and Configuration of Excel 6 March 20th 09 05:49 PM
Changing default fie for backup saving GrammyBarb Excel Discussion (Misc queries) 2 September 29th 08 10:10 PM
Why is Word, Excel saving a backup copy in my temp directory? daddyribs Excel Discussion (Misc queries) 1 April 19th 06 04:24 PM
Saving excel backup copy - path? ac Excel Discussion (Misc queries) 1 February 4th 05 09:26 PM
Backup in Saving a file in Excel 2002 4rs Excel Discussion (Misc queries) 1 January 14th 05 05:09 AM


All times are GMT +1. The time now is 01:17 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"