+ Reply to Thread
Results 1 to 3 of 3

Save Archive Once a Day

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Save Archive Once a Day

    I put the following code in the "this worksheet" section and it runs every time I open the spreadsheet. It saves an archive with the date and time, reopens the original and then closes the archive. I would like to program the macro to run upon open only if it hasn't been saved in 6 hours. Any ideas?




    Private Sub Workbook_Open()
    
    Resp = MsgBox("Save Archive? .", vbYesNo)
    
    If Resp = vbYes Then
    
    Dim wb As Workbook
    
    
    '----Saving Part
    Dim newFileName As String
    Application.DisplayAlerts = False
        
        
           newFileName = "Fix It Report Archive" & Format(Now, " MM-DD HHMM") & ".xlsm"
           
        
    ActiveWorkbook.SaveAs Filename:="M:\My Folder\Karen Postiglioni\JP\Template REPORTS\Tool Archives\\" & newFileName
    
     Workbooks.Open Filename:= _
            "M:\My Folder\Karen Postiglioni\JP\Template REPORTS\Template QA2.xlsm"
            
    For Each wb In Workbooks
    If Left(wb.Name, 21) = "Fix It Report Archive" Then
    wb.Close
    End If
    Next
    
    Application.DisplayAlerts = True
    Windows("Template QA2").Activate
    
    End If
    
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Save Archive Once a Day

    Private Sub Workbook_Open()
    
    If Now() < 0.25 * ThisWorkbook.Sheet1.Range("A1").Value Then Exit Sub
    
    Resp = MsgBox("Save Archive? .", vbYesNo)
    
    If Resp = vbYes Then
    
    Dim wb As Workbook
    
    
    '----Saving Part
    Dim newFileName As String
    Application.DisplayAlerts = False
        
        
           newFileName = "Fix It Report Archive" & Format(Now, " MM-DD HHMM") & ".xlsm"
           
        
    ActiveWorkbook.SaveAs Filename:="M:\My Folder\Karen Postiglioni\JP\Template REPORTS\Tool Archives\\" & newFileName
    
     Workbooks.Open Filename:= _
            "M:\My Folder\Karen Postiglioni\JP\Template REPORTS\Template QA2.xlsm"
            
    For Each wb In Workbooks
    If Left(wb.Name, 21) = "Fix It Report Archive" Then
    wb.Close
    End If
    Next
    
    Application.DisplayAlerts = True
    Windows("Template QA2").Activate
    ThisWorkbook.Sheet1.Range("A1").Value = Now()
    
    End If
    Elegant Simplicity............. Not Always

  3. #3
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: Save Archive Once a Day

    This worked. Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1