Hi
I Have Code Auto Save Every 5 Minutes But Dont Work Code
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub
Hi
I Have Code Auto Save Every 5 Minutes But Dont Work Code
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub
You need to more subs.
The Workbook_Open sub starts it all by calling WhentoSave
WhenToSave waits 5 minutes then calls SaveThis.
SaveThis saves the book then calls WhenToSave, starting the loop again.
[VBA]Option Explicit
Private Sub Workbook_Open()
WhenToSave
End Sub
Private Sub WhenToSave()
Application.OnTime Now + TimeValue("00:05:00"), "SaveThis"
End Sub
Private Sub SaveThis()
Me.Save
WhenToSave
End Sub
[/VBA]
I expect the student to do their homework and find all the errrors I leeve in.
Please take the time to read the Forum FAQ
Greetings,
A little different take, as I find it easier/simpler to call the sub in a Standard Module. Also, I believe you will want to handle cancelling the OnTime when the workbook gets closed (lest Excel will still want to run it).
In the ThisWorkbook Module:
[VBA]Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime timeNextSave, "SaveAgain", , False
End Sub
Private Sub Workbook_Open()
SaveAgain
End Sub[/VBA]
In a Standard Module:
[VBA]Option Explicit
Public timeNextSave As Date
Public Sub SaveAgain()
ThisWorkbook.Save
timeNextSave = Now + TimeSerial(0, 5, 0)
Application.OnTime timeNextSave, "SaveAgain", , True
End Sub[/VBA]
Hope that helps,
Mark
ACK.. Change the declaration for timeNextSave to Private. I was trying something different for a moment, and forgot to scope the variable back down...
Some days I wonder what life would be like...if only my brain worked better.
Since you want to save the workbook, this is an intervention on the workbook level.
That's why I would prefer to put all the code into the workbook macromodule:
[VBA]
Private Sub Workbook_Open()
ThisWorkbook.CustomDocumentProperties.Add "shed1", False, 3, Now
schedule
End Sub
Sub schedule()
ThisWorkbook.CustomDocumentProperties("shed1").Value = DateAdd("n", 5, Now)
Application.OnTime ThisWorkbook.CustomDocumentProperties("shed1").Value, "schedule"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime ThisWorkbook.CustomDocumentProperties("shed1").Value, "schedule", , False
End Sub
[/VBA]
Thank you GTO and snb for you help me
you can help me agian
I Need edit this code
Sub refresh()
'
' Macro2 Macro
'
' Keyboard Shortcut: Ctrl+k
'
ActiveWorkbook.RefreshAll
End Sub
i need code refresh and auto save every 5 minutes
i hope help me
With the suggestions provided you can easily accomplish that yourself; please take that opportunity !
Thank youOriginally Posted by snb
Add the Refresh code to the SaveThis sub above. BTW, all my code above goes in the ThisWorkbook Code Page.
About the "Me" Keyword: Me always refers to the Object of the Class Module it is in.
- In ThisWorkbook: Me = Only ThisWorkbook, not always the Active workbook.
- In UserForm Code Module: Me = ThisForm, not any other form.
- In custom Class Module: Me = ThisCustomObject
I expect the student to do their homework and find all the errrors I leeve in.
Please take the time to read the Forum FAQ