Close Method
Applies To
Document object, Documents collection object, Pane object, Task object, Window object.
Description
Syntax 1: Closes the specified document or documents.
Syntax 2: Closes the specified window.
Syntax 3: Closes the specified pane or task.
Syntax 1
expression.Close(SaveChanges, OriginalFormat, RouteDocument)
Syntax 2
expression.Close(SaveChanges, RouteDocument)
Syntax 3
expression.Close
expression Syntax 1: Required. An expression that returns a Document or Documents object.
Syntax 2: Required. An expression that returns a Window object.
Syntax 3: Required. An expression that returns a Pane or Task object.
SaveChanges Optional Variant. Specifies the save action for the document. Can be one of the following WdSaveOptions constants: wdDoNotSaveChanges, wdPromptToSaveChanges, or wdSaveChanges.
OriginalFormat Optional Variant. Specifies the save format for the document. Can be one of the following WdOriginalFormat constants: wdOriginalDocumentFormat, wdPromptUser, or wdWordDocument.
RouteDocument Optional Variant. True to route the document to the next recipient. If the document doesn't have a routing slip attached, this argument is ignored.
See Also
Documents property, Open method, Save method, SaveAs method, Split property.
Example
This example closes the active window and saves the document that's displayed in it.
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 ActiveWindow.Panes.Count >= 2 Then ActiveWindow.ActivePane.Close