0

期望的行为:当下面的代码完成时,MS Word 应该关闭并保持关闭状态。

问题:问题是 MS Word 应用程序重新启动并打开“Instructions.docx”,其中包含指向 Normal.dotm 的 Module1 中的以下 VBA Sub 的宏按钮。

仅供参考:(1)我第一次发帖。(2) 在我进行一些 Windows 10 和 Office 365 更新之前,大约六个月没有出现这个问题。(3) Office 365 MSO (16.0.12527.20260) 32 位的 MS Word。(4) Windows 10 Pro,64 位操作系统,i5-6500 @ 2.5 GHz,8 GB RAM。

问题:当我的 Normal.dotm VBA 关闭时,如何让 MS Word 应用程序保持关闭状态?

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
4

1 回答 1

1

通过将第 3 节修​​改为以下内容来修复:

'(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.
于 2021-04-20T22:14:56.650 回答