E
eric g
Hello, I'm an experienced Excel VBA coder, but very new to Word VBA.
I want to write some code to get Word to prompt me after 2 minutes to
save an unsaved document, and to autosave a document every 2 minutes
thereafter. Here's what I have so far:
In Normal - Microsoft Word Objects - This Document, I have this code:
Private Sub Document_Open()
Call InitializeAutoSave
End Sub
In Normal - Modules - New Macros, I have these two subs:
Sub InitializeAutoSave()
Application.OnTime When:=Now + TimeValue("00:02:00"),
Name:="AutoSaveMacro"
End Sub
Sub AutoSaveMacro()
MsgBox ActiveDocument.Saved
ActiveDocument.Save
MsgBox "Jo, your document has been saved."
Call InitializeAutoSave
End Sub
It only works if I open Word by double-clicking an already-saved Word
file on the Windows desktop or in the Windows Explorer. If I open
Word and then open an already-saved file, it doesn't work. If I open
Word with a blank new document, it doesn't work, either. I would
imagine this wouldn't require massive coding to get this to work, but
I could be wrong. I suspect I need to do some ActiveDocument.Saved
testing perhaps, among other things.
Again, I'm wanting the AutoSave code to save every active document
(any document I activate on the screen) every two minutes.
Thank you.
I want to write some code to get Word to prompt me after 2 minutes to
save an unsaved document, and to autosave a document every 2 minutes
thereafter. Here's what I have so far:
In Normal - Microsoft Word Objects - This Document, I have this code:
Private Sub Document_Open()
Call InitializeAutoSave
End Sub
In Normal - Modules - New Macros, I have these two subs:
Sub InitializeAutoSave()
Application.OnTime When:=Now + TimeValue("00:02:00"),
Name:="AutoSaveMacro"
End Sub
Sub AutoSaveMacro()
MsgBox ActiveDocument.Saved
ActiveDocument.Save
MsgBox "Jo, your document has been saved."
Call InitializeAutoSave
End Sub
It only works if I open Word by double-clicking an already-saved Word
file on the Windows desktop or in the Windows Explorer. If I open
Word and then open an already-saved file, it doesn't work. If I open
Word with a blank new document, it doesn't work, either. I would
imagine this wouldn't require massive coding to get this to work, but
I could be wrong. I suspect I need to do some ActiveDocument.Saved
testing perhaps, among other things.
Again, I'm wanting the AutoSave code to save every active document
(any document I activate on the screen) every two minutes.
Thank you.