Word: File and Close VBA time saver
Hi All,
I do lots of client Word files every hour,
and created a macro to close them after I have saved.
So you leave the Word App open and save about 5 seconds
when run via the above ribbon short cut. I changed the
Symbol to "X".
This works very well, if you have saved or unsaved files
open, and even if a protected view file is downloaded from
a web browser.
For a standard work day, if you use 52/53 times, I save
1% of my work hours, so 1% more efficient from just this
macro, which is not my main time saving macros in
Outlook and Word.
This one drove me a bit nuts to get it to work.
Is there a better way to code this? It works fine so far.
I have copied the macro into Excel and adjusted, so
is adjustable.
Code:
Sub WordFileClose()
'SOURCE: James Martin - May be simpler vba to do this but I could not work out other methods, this works.
Word.Application.screenupdating = False
Dim WrdPV As ProtectedViewWindow
If Word.Application.ProtectedViewWindows.Count >= 0 Then GoTo Normal
'this formula counts open and recent (viewable via right clicking on WordApp in Taskbar).
Protected: If Word.Application.Documents.Count >= 0 Then GoTo NoDoc
NoDoc: If Word.Application.ProtectedViewWindows.Count = 0 Then
Exit Sub
End If
Word.ActiveProtectedViewWindow.Edit
Word.ActiveDocument.Close
Exit Sub
Normal: On Error GoTo Protected
Word.ActiveDocument.Close
Exit Sub
Word.Application.screenupdating = False
Exit Sub
End Sub