Close Method

Microsoft Word Visual Basic

Closes the specified document or documents.

expression.Close(SaveChanges, OriginalFormat, RouteDocument)

expression    Required. An expression that returns one of the above objects.

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.

ShowClose method as it applies to the MailMergeDataSource, Pane, and Task objects.

Closes the specified Mail Merge data source, pane, or task.

expression.Close

expression    Required. An expression that returns one of the above objects.

ShowClose method as it applies to the Window object.

Closes the specified window.

expression.Close(SaveChanges, RouteDocument)

expression    Required. An expression that returns one of the above objects.

SaveChanges   Optional Variant. Specifies the save action for the document. Can be one of the following WdSaveOptions constants: wdDoNotSaveChanges, wdPromptToSaveChanges, or wdSaveChanges.

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.

Example

ShowAs it applies to the Document object.

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"
				

ShowAs it applies to the Pane object.

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

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

ShowAs it applies to the Task object.

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
				

ShowAs it applies to the Window object.

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

ActiveDocument.ActiveWindow.Close SaveChanges:=wdSaveChanges