Save related procedures in class Document (Word VBA)

This page presents procedures from class Document related to the theme Save: AutoSaveOn, CanCheckin, CheckIn, CheckInWithVersion, IsInAutosave, Save, SaveAs2, Saved, SaveEncoding and Documents.Save

AutoSaveOn

True if the edits in the document are automatically saved.

When a new document is created, the default value for the AutoSaveOn property is False, the property is disabled, and the user's changes will need to be saved manually. However, if the document is hosted on the cloud (that is, OneDrive, OneDrive for Business, or SharePoint Online), then the AutoSaveOn property defaults to True and the edits in the specified document are automatically saved. If a cloud-hosted document is shared with other users, then their changes will also be automatically merged into the user's local copy when AutoSaveOn is True. Table 1 AutoSaveOn behavior

Sub UseAutoSaveOn()
    MsgBox "This document is being saved automatically: " & ActiveDocument.AutoSaveOn
End Sub

CanCheckin

True if Microsoft Word can check in a specified document to a server.

To take advantage of the collaboration features built into Word, documents must be stored on a Microsoft SharePoint Portal Server.

Sub CheckInOut(docCheckIn As String) 
 If Documents(docCheckIn).CanCheckin = True Then 
 Documents(docCheckIn).CheckIn 
 MsgBox docCheckIn & " has been checked in." 
 Else 
 MsgBox "This file cannot be checked in " & _ 
 "at this time. Please try again later." 
 End If 
End Sub

CheckIn

Returns a document from a local computer to a server, and sets the local document to read-only so that it cannot be edited locally.

To take advantage of the collaboration features built into Microsoft Word, documents must be stored on a Microsoft SharePoint Portal Server.

Syntax : expression.CheckIn (SaveChanges, Comments, MakePublic)

Sub CheckInOut(docCheckIn As String) 
 If Documents(docCheckIn).CanCheckin = True Then 
 Documents(docCheckIn).CheckIn 
 MsgBox docCheckIn & " has been checked in." 
 Else 
 MsgBox "This file cannot be checked in " & 
 "at this time. Please try again later." 
 End If 
End Sub

Arguments

The following arguments are optional

SaveChanges (Boolean) - True saves the document to the server location. The default is True.

Comments (String) - Comments for the revision of the document being checked in (only applies if SaveChanges equals True).

MakePublic (Boolean) - True allows the user to perform a publish on the document after being checked in. This submits the document for the approval process, which can eventually result in a version of the document being published to users with read-only rights to the document (only applies if SaveChanges equals True). The default is False.

CheckInWithVersion

Saves a document to a server from a local computer, and sets the local document to read-only so that it cannot be edited locally.

Setting the MakePublic parameter to True submits the document for the approval process, which can eventually result in a version of the document being published to users with read-only rights to the document (applies only if SaveChanges is set to True). To take advantage of the collaboration features built into Microsoft Word, documents must be stored on a Microsoft SharePoint Server.

Syntax : expression.CheckInWithVersion (SaveChanges, Comments, MakePublic, VersionType)

Private Sub DocumentCheckIn() 
 If ActiveDocument.CanCheckin Then 
 ActiveDocument.CheckInWithVersion _ 
 True, _ 
 "My updates.", _ 
 True, _ 
 WdCheckInVersionType.wdCheckInMinorVersion 
 Else 
 MessageBox.Show ("This document cannot be checked in") 
 End If 
End Sub

Arguments

The following arguments are optional

SaveChanges (Boolean) - True to save the document to the server location. The default is True.

Comments (String) - Comments for the revision of the document being checked in (applies only if SaveChanges is set to True).

MakePublic (Boolean) - True to allow the user to publish the document after it is checked in.

VersionType (Document) - Specifies versioning information for the document.

IsInAutosave

Returns False if the most recent firing of the Application.DocumentBeforeSave event (Word) event was the result of a manual save by the user, and not an automatic save.

The IsInAutosave property is designed to be used in an event handler for the Application.DocumentBeforeSave event. Using it for other purposes is not recommended.

If Word.ActiveDocument.IsInAutosave = False Then
   Debug.Print "Manual save."
Else
   Debug.Print "Automatic save."
End If

Save

Saves the specified document.

If a document has not been saved before, the Save As dialog box prompts the user for a file name.

If ActiveDocument.Saved = False Then ActiveDocument.Save

SaveAs2

Saves the specified document with a new name or format. Some of the arguments for this method correspond to the options in the Save As dialog box (File tab).

Syntax : expression.SaveAs2 (FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter, Encoding, InsertLineBreaks, AllowSubstitutions, LineEnding, AddBiDiMarks, CompatibilityMode)

Sub SaveAsRTF() 
    ActiveDocument.SaveAs2 FileName:="Text.rtf", _ 
        FileFormat:=wdFormatRTF 
End Sub

Arguments

The following arguments are optional

FileName (String) - The name for the document. The default is the current folder and file name. If the document has never been saved, the default name is used (for example, Doc1.doc). If a document with the specified file name already exists, the document is overwritten without prompting the user.

FileFormat (FileConverter) - The format in which the document is saved. Can be any WdSaveFormat constant. To save a document in another format, specify the appropriate value for the SaveFormat property of the FileConverter object.

LockComments (Boolean) - True to lock the document for comments. The default is False.

Password (String) - A password string for opening the document. (See Remarks below.).

AddToRecentFiles (Boolean) - True to add the document to the list of recently used files on the File menu. The default is True.

WritePassword (String) - A password string for saving changes to the document. (See Remarks below.).

ReadOnlyRecommended (Boolean) - True to have Microsoft Word suggest read-only status whenever the document is opened. The default is False.

EmbedTrueTypeFonts (Boolean) - True to save TrueType fonts with the document. If omitted, the EmbedTrueTypeFonts argument assumes the value of the EmbedTrueTypeFonts property.

SaveNativePictureFormat (Boolean) - If graphics were imported from another platform (for example, Macintosh), True to save only the Microsoft Windows version of the imported graphics.

SaveFormsData (Boolean) - True to save the data entered by a user in a form as a record.

SaveAsAOCELetter (Boolean) - If the document has an attached mailer, True to save the document as an AOCE letter (the mailer is saved).

Encoding (String) - The code page, or character set, to use for documents saved as encoded text files. The default is the system code page. You cannot use all MsoEncoding constants with this parameter.

InsertLineBreaks (Boolean) - If the document is saved as a text file, True to insert line breaks at the end of each line of text.

AllowSubstitutions (Boolean) - If the document is saved as a text file, True allows Word to replace some symbols with text that looks similar. For example, displaying the copyright symbol as (c). The default is False.

LineEnding (WdLineEndingType) - The way Word marks the line and paragraph breaks in documents saved as text files. Can be one of the following WdLineEndingType constants: wdCRLF (default) or wdCROnly.

Possible Values are

wdCRLF Carriage return plus line feed.
wdCROnly Carriage return only.
wdLFCR Line feed plus carriage return.
wdLFOnly Line feed only.
wdLSPS Not supported.

AddBiDiMarks (Boolean) - True adds control characters to the output file to preserve bi-directional layout of the text in the original document.

CompatibilityMode (WdCompatibilityMode) - The compatibility mode that Word uses when opening the document. WdCompatibilityMode constant.Important By default, if no value is specified for this parameter, Word enters a value of 0, which specifies that the current compatibility mode of the document should be retained.

Possible Values are

wdCurrent Compatibility mode equivalent to the latest version of Word.
wdWord2003 Word is put into a mode that is most compatible with Word 2003. Features new to Word are disabled in this mode.
wdWord2007 Word is put into a mode that is most compatible with Word 2007. Features new to Word are disabled in this mode.
wdWord2010 Word is put into a mode that is most compatible with Word 2010. Features new to Word are disabled in this mode.
wdWord2013 Default. All Word features are enabled.

Saved

True if the specified document or template has not changed since it was last saved. False if Microsoft Word displays a prompt to save changes when the document is closed.

If ActiveDocument.Saved = False Then ActiveDocument.Save

SaveEncoding

Returns or sets the encoding to use when saving a document.

ActiveDocument.SaveEncoding = msoEncodingWestern

Documents.Save

Saves all the documents in the Documents collection.

If a document has not been saved before, the Save As dialog box prompts the user for a file name.

Syntax : expression.Save (NoPrompt, OriginalFormat)

Documents.Save

Arguments

The following arguments are optional

NoPrompt (Boolean) - True to have Word automatically save all documents. False to have Word prompt the user to save each document that has changed since it was last saved.

OriginalFormat (WdOriginalFormat) - Specifies the way the documents are saved. Can be one of the WdOriginalFormat constants.

Possible Values are wdOriginalDocumentFormat - Original document format, wdPromptUser - Prompt user to select a document format, wdWordDocument - Microsoft Word document format.