LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Refresh & backup tuning!

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Excel functions formula and auto refresh refresh Pauline Cheong Excel Worksheet Functions 3 February 16th 09 01:23 AM
Create refresh button in worksheet to refresh Pivot Table Data Ron Excel Worksheet Functions 1 October 13th 07 01:20 AM
help w/ fine tuning Mike New Users to Excel 1 October 19th 05 08:58 PM
Pivot Table REFRESH Flaw -- Saves Old Data in Selection Area AFTER REFRESH Ken Roberts Excel Programming 3 September 11th 03 06:02 AM
Excel does not close from VB!! (when i refresh Refresh query with BackgroundQuery:=False) Anant[_2_] Excel Programming 1 August 6th 03 04:22 AM


All times are GMT +1. The time now is 08:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"