Refresh & backup tuning!

R

Rhonda

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top