Advertisement

09.29.2008 at 08:44PM PDT, ID: 23773629
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Backup macro that saves and zips workbooks every 90 mins - change filename for first backup every day.

Asked by RichardRowe in Microsoft Excel Spreadsheet Software

Tags: ,

Hi experts,

The following macro creates a backup of a file by saving it, then zipping it and moving it into a folder.  When the workbook is open this macro is automatically called on by another macro every 90 minutes.  The zip file is automatically named in the format "(workbook file name),date,hh:mm:ss.

What I want to happen is the first backup of the day will have a different file name to the rest of the files backed up on that day.  So the first backup on monday will be named "First_Mon_workbook file name,date,hh:mm:ss"

Is this possible?

Cheers
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
Sub Zip_ThisWorkbook()
    Dim strDate As String, StrDateBUpFolder As String, DefPath As String, DefPathBackup As String
    Dim FileNameOriginZip, FileNameXls, FileNameDestinationZip, FileNameBUp
    Dim oApp As Object
 
 
    Application.DisplayStatusBar = True 'turns on the status bar
    Application.StatusBar = "Please wait while File is Saved and Zipped" ' displays a message in Status Bar
 
    Application.ScreenUpdating = False  ' Hides changes to screen until Macro finished
 
    'Define This workbook Path and Backup Folder date to use
    DefPath = ThisWorkbook.Path & "\"
    StrDateBUpFolder = Format(Now, "mmmyyyy")
  
    'Checks to See If A Directory Exists, If Not, Creates It
    DefPathBackup = ThisWorkbook.Path & "\" & "Enrol Backup" & StrDateBUpFolder & "\"
    DirTest = Dir$(DefPathBackup, vbDirectory)
        If DirTest = "" Then
            MkDir DefPathBackup
            DoEvents    'just to make sure it is there
        End If
        
   'Create date/time string and the temporary xls and zip file name
    strDate = Format(Now, " (ddd dmmmyy hmmam/pmss") & "sec)"
    FileNameBUp = Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) & strDate & ".zip"
    FileNameDestinationZip = DefPathBackup & FileNameBUp 'Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) & strDate & ".zip"
    FileNameOriginZip = DefPath & FileNameBUp 'Left(ThisWorkbook.Name, Len(ThisWorkbook.Name) - 4) & strDate & ".zip"
    FileNameXls = DefPath & ThisWorkbook.Name
  
    If Dir(FileNameOriginZip) = "" Then ' And Dir(FileNameXls) = "" Then
        
        'Make copy of the Thisworkbook
        ThisWorkbook.Save
 
        'Create empty Zip File
        Application.ScreenUpdating = False  ' Hides changes to screen until Macro finished
        NewZip (FileNameOriginZip)
 
        'Copy the file in the compressed folder
        Set oApp = CreateObject("Shell.Application")
        oApp.Namespace(FileNameOriginZip).CopyHere FileNameXls
 
        'Keep script waiting until Compressing is done
        On Error Resume Next
        Do Until oApp.Namespace(FileNameOriginZip).items.Count = 1
            Application.Wait (Now + TimeValue("0:00:01"))
        Loop
        On Error GoTo 0
 
        ' Move Zipped file to Backup Directory
        Name FileNameOriginZip As FileNameDestinationZip
        
        Else
    End If
    
    MsgBox "This file has been Saved and Zipped - Om Tat Sat"
    
    Application.StatusBar = False 'turns off Message
    Application.ScreenUpdating = True ' Turns back on screen updating
    
End Sub
 
Sub NewZip(sPath)
'Create empty Zip File
'Changed by keepITcool Dec-12-2005
    If Len(Dir(sPath)) > 0 Then Kill sPath
    Open sPath For Output As #1
    Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
    Close #1
End Sub
[+][-]09.29.2008 at 11:53PM PDT, ID: 22603231

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Tags: Microsoft, Excel
Sign Up Now!
Solution Provided By: valentpe
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628