Prompting to save at interval

sriche01

Board Regular
Joined
Dec 24, 2013
Messages
136
Office Version
  1. 365
Platform
  1. Windows
Hello all,

Is there a way to make a workbook require or remind a user to save at a set interval, say, every ten minutes? Didn't see it in options...
Thanks!
 
Thank you for your patience with me Pat. I think it is working the way I want now! Much appreciated!
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
No, actually you'll need to dim the variable as "Public" in the code module.
Sorry about that. I hadn't tested that part.

Code:
Option Explicit
Public RunWhen As Double
 
Upvote 0
OK, one more issue. I had been running this in a dummy program while working out the code. Now that it behaves the way I wanted, I copied the code into the appropriate modules in the file it was created for. However, when SaveTimer expires and it is time to save, it opens my dummy program and requests me to save both that file and the real one. For reference my code is below:
In a Workbook space:
Code:
Option Explicit


Private Sub Workbook_AfterSave(ByVal Success As Boolean)
   
On Error Resume Next
   If Not IsNull(RunWhen) Then
            'cancel current timer
            CancelEarly
        
            'start new timer
            StartSaveTimer
    End If
End Sub


Private Sub Workbook_Open()
        If Not ActiveWorkbook.ReadOnly Then
                StartSaveTimer
    End If
End Sub
Then in a module

Code:
Option Explicit
Public RunWhen As Double


Sub StartSaveTimer()
        RunWhen = Now + TimeValue("00:10:00")
        Application.OnTime RunWhen, "AskToSave", , True
End Sub


Sub AskToSave()
        
        If MsgBox("Do you want to save?" & Chr(10) & Chr(13) & Chr(10) & Chr(13) & "Select Yes to Save, Select No to be reminded Later" & Chr(10) & Chr(13) & Chr(10) & Chr(13) & "Last save was at " & ThisWorkbook.BuiltinDocumentProperties(12), vbYesNo, "Time to Save Master File") = vbYes Then
            '  the after save event also re-starts the timer
            ThisWorkbook.Save
    Else
            StartSaveTimer
    End If
End Sub


Sub CancelEarly()
       On Error Resume Next
       Application.OnTime RunWhen, "AskToSave", , False
End Sub

Somehow, the code meant for one file is calling the sub for the other file. How do I keep this from happening? I want to keep the dummy file in case I want to keep formatting the message box or make other tweaks.

Thanks!
 
Upvote 0
See if this helps.... specifying the workbook to save...


Code:
Private Sub Workbook_Open()
    If Not ActiveWorkbook.ReadOnly Then
        wbToSave = ActiveWorkbook
        StartSaveTimer
    End If
End Sub


Then in the code module:

Code:
Option Explicit
Public RunWhen As Double
Public wbToSave As Workbook
Sub StartSaveTimer()
    RunWhen = Now + TimeValue("00:10:00")
    Application.OnTime RunWhen, "AskToSave", , True
End Sub

Sub AskToSave()
        
    If MsgBox("Do you want to save?" & vbCrLf & vbCrLf & "Select Yes to Save, Select No to be reminded Later" & vbCrLf & vbCrLf & "Last save was at " & ThisWorkbook.BuiltinDocumentProperties(12), vbYesNo, "Time to Save Master File") = vbYes Then
        '  the after save event also re-starts the timer
        wbToSave.Save
    Else
        StartSaveTimer
    End If
End Sub

Sub CancelEarly()
    On Error Resume Next
    Application.OnTime RunWhen, "AskToSave", , False
End Sub

Note: vbCrLf = Carriage return + Line Feed (Chr(10) + Chr(13))
 
Upvote 0
Thanks Pat. I tried this, but it won't accept the variable wbToSave. Error 91 variable not defined. Any ideas? Thanks!
 
Upvote 0
Update for those of you just tuning in...

I've got code to run a timer so that every 10 minutes a messagebox pops up prompting to save (see code in previous posts).

The problem I currently face is that if I have a copy of this workbook open with a different filename but the same code, when the timer is activated for the open workbook, it also opens any other workbooks with the same code to give a message box asking to save that workbook too. Sometimes the two workbooks are synced on the same interval and other times they are not.

But I repeat, the code opens a closed workbook to run IF I have another open running the same code.

Either the code needs rearranging or we need a stop procedure or something.

Any Ideas? Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top