Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi.
I have the code below that creates a backup of a spreadsheet. I also have code to refresh all of my web queries at month end. I need to change the refresh from month end to the 24th of each month and a way to error so that if for some reason it was conducted on the 24th, it could be carried out at any other day within that month. (To make sure no data is lost). My backup button also needs some fine tuning to first check to see if the refresh occurred, and only then, allow the backup to be created. Then if it has been created, I don't want the backup to take place. Please help!!! Private Sub Backup_Button_Click() Dim awb As Workbook, BackupFileName As String, i As Integer, OK As Boolean If TypeName(ActiveWorkbook) = "Nothing" Then Exit Sub Set awb = ActiveWorkbook If awb.Path = "" Then Application.Dialogs(xlDialogSaveAs).Show Else BackupFileName = awb.FullName i = 0 While InStr(i + 1, BackupFileName, ".") 0 i = InStr(i + 1, BackupFileName, ".") Wend If i 0 Then BackupFileName = Left (BackupFileName, i - 1) 'BackupFileName = BackupFileName & ".bak" OK = False On Error GoTo NotAbleToSave If Dir(Left(ThisWorkbook.FullName, Len (ThisWorkbook.FullName) - 4) & _ Format(Date, "_yyyy_mm") & ".bak") < "" Then MsgBox "File Already Exists!", vbExclamation, ThisWorkbook.Name Else With awb Application.StatusBar = "Saving this workbook..." .Save Application.StatusBar = "Saving this workbook backup..." ThisWorkbook.SaveCopyAs Left (ThisWorkbook.FullName, Len( _ ThisWorkbook.FullName) - 4) & Format (Date, "_yyyy_mm") & ".bak" '.SaveCopyAs BackupFileName OK = True End With End If End If NotAbleToSave: Set awb = Nothing Application.StatusBar = False If Not OK Then MsgBox "Backup Copy Not Saved!", vbExclamation, ThisWorkbook.Name Else MsgBox "Backup was successful!", vbInformation, ThisWorkbook.Name End If End Sub Private Sub Refresh_Button_Click() If Date = DateSerial(Year(Date), Month(Date) + 1, 0) Then MsgBox "This is the last day of the Month. Your data will be updated." ' RefreshMeters Macro ' Macro recorded 30/09/2003 by rhocarit ' ' Keyboard Shortcut: Ctrl+a ' ActiveWorkbook.RefreshAll Else MsgBox "This is NOT the last day of the Month. Your data has NOT been updated." End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copy Excel functions formula and auto refresh refresh | Excel Worksheet Functions | |||
Create refresh button in worksheet to refresh Pivot Table Data | Excel Worksheet Functions | |||
help w/ fine tuning | New Users to Excel | |||
Pivot Table REFRESH Flaw -- Saves Old Data in Selection Area AFTER REFRESH | Excel Programming | |||
Excel does not close from VB!! (when i refresh Refresh query with BackgroundQuery:=False) | Excel Programming |