Desired Behavior: When the below code completes, MS Word is supposed to close and remain closed.
Problem: The problem is that the MS Word application re-starts and opens "Instructions.docx," which has the macro-button that points to the below VBA Sub in Module1 of Normal.dotm.
FYIs: (1) My first time posting. (2) This problem was not happening about six months, before I took some Windows 10 & Office 365 updates. (3) MS Word for Office 365 MSO (16.0.12527.20260) 32-bit. (4) Windows 10 Pro, 64-bit OS, i5-6500 @ 2.5 GHz, 8 GB RAM.
Question: How do I get the MS Word application to stay closed when my Normal.dotm VBA closes it?
Sub Finishing()
'To reset and save Instruction.docx
'To move existing Outputs folder to a new date-specific destination
'To close all open *.docx's then quit MS Word application
Dim TodaysYear, FridaysDate, ToPath, FromPath As String
'(1) Reset_All_Checkboxes as adapted from Greg Maxey
Dim oCC As ContentControl
For Each oCC In ActiveDocument.Range.ContentControls
oCC.Checked = False
Next
'(2) Move_and_Rename_Outputs_Dir as adapted from Ron de Bruin
ToPath = "C:\Users\me\OneDrive\Documents\Trade Records\" & Format(Date, "yyyy") & "\" & Format(DateAdd("d", 4, Date), "yyyy-mm-dd") 'add 4 days
FromPath = "C:\Users\me\OneDrive\Documents\Outputs"
Dim FSO As Object
Set FSO = CreateObject("scripting.filesystemobject")
FSO.MoveFolder Source:=FromPath, Destination:=ToPath
'(3) Save and close all open files then quit Word
With Application
.ScreenUpdating = False
'Loop through open documents
Do Until .Documents.Count = 0
.Documents(1).Close SaveChanges:=wdSaveChanges
Loop
.Quit SaveChanges:=wdSaveChanges 'Quit MS Word
End With
End Sub
Fixed by amending section 3 to the following:
'(3) Save Instructions.docx without prompts then prompt to close all open files then quit Word
'This achieves Desired Behavior: Instructions.docs exit-macro runs without problem of re-opening MS Word application after the Word macro closes the Instructions document & exits the Word application
Documents("Instructions .docx").Activate
ActiveDocument.Save 'if Instructions.docx is the only open Word doc, macro completes without prompt
Application.Quit SaveChanges:=wdDoNotSaveChanges 'This saves option is for changes to Normal.dotm. Other Save Options are wdSaveChanges & wdPromptToSaveChanges.