Consulting

Results 1 to 3 of 3

Thread: Word: File and Close VBA time saver

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    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.


    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
    Last edited by Aussiebear; 11-12-2021 at 06:49 AM. Reason: added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •