Close Method Example

This example closes the active window of the active document and saves it.

ActiveDocument.ActiveWindow.Close SaveChanges:=wdSaveChanges

This example prompts the user to save the active document before closing it. If the user clicks Cancel, error 4198 (command failed) is trapped and a message is displayed.

On Error GoTo errorHandler
ActiveDocument.Close _
    SaveChanges:=wdPromptToSaveChanges, _
    OriginalFormat:=wdPromptUser
errorHandler:
If Err = 4198 Then MsgBox "Document was not closed"

This example activates Microsoft Excel and then closes it.

For Each myTask In Tasks
    If InStr(myTask.Name, "Microsoft Excel") > 0 Then
        myTask.Activate
        myTask.Close
    End If
Next myTask

This example closes the active pane if the active window is split.

If ActiveDocument.ActiveWindow.Panes.Count >= 2 Then _
    ActiveDocument.ActiveWindow.ActivePane.Close