How To Back Up Your Excel Lotto Data Using VBA

103 12
If you've been working with Excel files in lotto research you should know how important it is to back up your files.
While Excel has its own tools for saving your work, it makes sense to take control of your own data.
This article shows how you can automate the process of saving your work, every time the file is opened.
Running The VBA Code Whenever The Excel File Is Opened You'll need to do two things to create the "set and forget" back up module.
  • Write a VBA start procedure in the "Workbook" section of the code module
  • Complete the code in a standard module to copy and rename the file
The start procedure is simply a one line VBA script which runs whenever the Excel file is opened.
It's important the code is placed in the "This Workbook" section of the VBA coding environment.

Sub workbook_open() backUpFile End Sub The code instructs VBA to run the "backUpFile" module whenever the work book is opened.
Copying And Saving The Current Work Book With VBA The "backUpFile" program defines a new name for the file and saves it in the same folder.
The name you give the new file depends on how you structure your work.
For example:
  • Use the current date in the naming structure
  • A generic "backup" prefix in front of the current file name
First we'll define the old and new file names.
In this case we've opted for a simple naming regime and just placed the string "backUp" in front of the existing file name.

Sub backUpFile() Dim fs As Object f1 = ActiveWorkbook.
Path & "\myFile.
xls" f2 = ActiveWorkbook.
Path & "\backUpMyFile.
xls" Now we can run the code for copying the file.

Set fs = CreateObject("Scripting.
FileSystemObject") fs.
CopyFile f1, f2 Set fs = Nothing end sub Further Development Of The VBA Back Up Module If you need more complexity in the back up name, you could add the current date as part of the naming structure.

months = Split(",Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", ",") dte = Day(Now) & months(Month(Now)) & Year(Now) dte = Hour(Now) & "_" & Minute(Now) & "_" & dte dte=dte & "myFile.
xls" In the above example the structure of the new file name now looks something like this.
:
9_1_29Apr2014myFile.
xls This naming regime above might be useful if you're opening and closing the file throughout the day.
At some point the backup files might become a little too many and you may need to delete some of them.
Of course you can always use VBA code to delete files as well.
Summary This article has highlighted the importance of backing up your lotto files and how a few lines of VBA code can save important data.
While data back ups may not help you win lotto, it makes your work more professional and hence more likely to be a success.
Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.