Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default "Backing" up a Workbook Sheet

I'm developing an Excel-based VBA program that performs
some calculations and updates on a master budget sheet.

However, before I allow the user to go modifying this
sheet, I would like to "back it up" to a new Excel
spreadsheet in the very-likely event I have to correct
their errors.

How do you copy/export/backup the entire workbook and/or
selected sheets to a new Excel workbook?

Thanks in advance for your help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default "Backing" up a Workbook Sheet

There are many ways to do this. Have you thought of using saveas or sheet
copy?

"Roy" wrote in message
...
I'm developing an Excel-based VBA program that performs
some calculations and updates on a master budget sheet.

However, before I allow the user to go modifying this
sheet, I would like to "back it up" to a new Excel
spreadsheet in the very-likely event I have to correct
their errors.

How do you copy/export/backup the entire workbook and/or
selected sheets to a new Excel workbook?

Thanks in advance for your help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default "Backing" up a Workbook Sheet

Roy,

If you want to do it as an event before the user gets at it, I would suggest
using the FileSystemObject in a Workbook_Open event. The problem with SaveAs
is that it changes the name of the workbook being worked upon (to whatever
was specified in SaveAs).

Private Sub Workbook_Open()

Dim oFSO As Object
Dim sThisFile As String
Dim sBackup As String

sThisFile = ThisWorkbook.FullName
sBackup = Left(sThisFile, Len(sThisFile) - 3) & Format(Now, "dd mmm yyyy
hh-mm-ss") & ".bak"

Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.copyfile sThisFile, sBackup
Set oFSO = Nothing

End Sub

The reason I use FSO rather than FileCopy is that FileCopy does not work on
an open file, which you need in this case.

The file saved is the original filename, without the 'xls' extension, and
with a date and time appended, and finally '.bak.' This will leave you as
many versions as you want to keep in the same folder.

This code is workbook code, so it goes in the ThisWorkbook code module.

--

HTH

Bob Phillips

"Roy" wrote in message
...
Mr. Walkenbach didn't cover those in his book (Excel 2000
Power Programming with VBA), or at least not in a way
that I could understand!

Could you provide some more detail or a reference site?


-----Original Message-----
There are many ways to do this. Have you thought of

using saveas or sheet
copy?

"Roy" wrote in message
...
I'm developing an Excel-based VBA program that performs
some calculations and updates on a master budget sheet.

However, before I allow the user to go modifying this
sheet, I would like to "back it up" to a new Excel
spreadsheet in the very-likely event I have to correct
their errors.

How do you copy/export/backup the entire workbook

and/or
selected sheets to a new Excel workbook?

Thanks in advance for your help!



.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default "Backing" up a Workbook Sheet

You may want to look at SaveCopyAs. It's documented in VBA's help.

Roy wrote:

Mr. Walkenbach didn't cover those in his book (Excel 2000
Power Programming with VBA), or at least not in a way
that I could understand!

Could you provide some more detail or a reference site?

-----Original Message-----
There are many ways to do this. Have you thought of

using saveas or sheet
copy?

"Roy" wrote in message
...
I'm developing an Excel-based VBA program that performs
some calculations and updates on a master budget sheet.

However, before I allow the user to go modifying this
sheet, I would like to "back it up" to a new Excel
spreadsheet in the very-likely event I have to correct
their errors.

How do you copy/export/backup the entire workbook

and/or
selected sheets to a new Excel workbook?

Thanks in advance for your help!



.


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 620
Default "Backing" up a Workbook Sheet

Roy posted a further question to me direct re deleting old files. I offered
this morsel, but I am also posting here in case anyone has an alternative.
BTW, Roy asked to keep a number, but I gave aged files, as the file has a
date property.

Bob

Roy,

Here's a little routine that deletes files not modified in a given time.

Sub DeleteOldFiles(path As String, Optional age As Long = 10)
Dim oFSO As Object, oFolder As Object
Dim oFiles As Object, oFile As Object
Dim cFiles As Long, i As Long
Dim sFiles As String

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(path)
Set oFiles = oFolder.Files

For Each oFile In oFiles
If oFile.DateLastModified < (Date - age) Then
cFiles = cFiles + 1
sFiles = sFiles & oFile.path & Chr(13)
oFile.Delete
End If
Next

MsgBox sFiles & Chr(13) & "are the files deleted"

End Sub

This is how you call it
DeleteOldFiles "c:\myTest\myTest"
or
DeleteOldFiles "c:\myTest\myTest", 25


"Bob Phillips" wrote in message
...
Roy,

If you want to do it as an event before the user gets at it, I would

suggest
using the FileSystemObject in a Workbook_Open event. The problem with

SaveAs
is that it changes the name of the workbook being worked upon (to whatever
was specified in SaveAs).

Private Sub Workbook_Open()

Dim oFSO As Object
Dim sThisFile As String
Dim sBackup As String

sThisFile = ThisWorkbook.FullName
sBackup = Left(sThisFile, Len(sThisFile) - 3) & Format(Now, "dd mmm

yyyy
hh-mm-ss") & ".bak"

Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.copyfile sThisFile, sBackup
Set oFSO = Nothing

End Sub

The reason I use FSO rather than FileCopy is that FileCopy does not work

on
an open file, which you need in this case.

The file saved is the original filename, without the 'xls' extension, and
with a date and time appended, and finally '.bak.' This will leave you as
many versions as you want to keep in the same folder.

This code is workbook code, so it goes in the ThisWorkbook code module.

--

HTH

Bob Phillips

"Roy" wrote in message
...
Mr. Walkenbach didn't cover those in his book (Excel 2000
Power Programming with VBA), or at least not in a way
that I could understand!

Could you provide some more detail or a reference site?


-----Original Message-----
There are many ways to do this. Have you thought of

using saveas or sheet
copy?

"Roy" wrote in message
...
I'm developing an Excel-based VBA program that performs
some calculations and updates on a master budget sheet.

However, before I allow the user to go modifying this
sheet, I would like to "back it up" to a new Excel
spreadsheet in the very-likely event I have to correct
their errors.

How do you copy/export/backup the entire workbook

and/or
selected sheets to a new Excel workbook?

Thanks in advance for 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
Backing up "Shared" Carolina Girl Setting up and Configuration of Excel 0 August 27th 09 07:46 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Excel "Move or Copy" and "Delete" sheet functions dsiama Excel Worksheet Functions 1 December 28th 07 01:57 PM
cannot use "Create List" and "Share Workbook" same time Devendra Excel Discussion (Misc queries) 0 October 26th 06 06:05 AM
Finding the "Size" of Each Sheet in a Workbook Tim Childs Excel Programming 4 July 27th 03 09:35 AM


All times are GMT +1. The time now is 11:27 PM.

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"