Saving Documents


Document.Save

If the document or template hasn't been saved before, this method will display the Save As dialog box and prompt the user to save the file.

Application.ActiveDocument.Save 
ActiveDocument.Save
Application.Documents("document.doc").Save
Documents("document.doc").Save
objDocument.Save

If the user presses the Cancel button on the SaveAs dialog box then an error will be generated.
To prevent this error you must catch the error and ignore it by using an On Error . Command.



Document.Saved

This property indicates if there are any unsaved changes in the document
It can also be set as a way of getting a document to close without a "do you want to save changes" prompt
Changing the property to True will flag the document as clean and disable the save button

If (ActiveDocument.Saved = False) Then 

End if



Document.SaveAs

Display the SaveAs dialog box allowing you to save a copy of that document or template.

ActiveDocument.SaveAs FileName:="C:\Temp\document.doc", _ 
                      FileFormat:=wdSaveFormat.wdFormatDocument, _
                      LockComments:=False, _
                      Password:=""
                      AddToRecentFiles:=True
                      WritePassword:=""
                      ReadOnlyRecommendation:=False
                      EmbedTrueTypeFonts:=False
                      SaveNativePictureFormat:=False
                      SaveFormatData:=False
                      SaveAsOCELetter:=False
                      Encoding:=
                      InsertLineBreaks:=
                      AllowSubstitutions:=
                      LineEnding:=
                      AddBiDiMarks:=

FileName - 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 the user being prompted first.
FileFormat -The format in which the document is saved. Can be any WdSaveFormat value. To save a document in another format, specify the appropriate value for the SaveFormat property.
LockComments - true to lock the document for comments. The default is false.
Password - A password string for opening the document. (See Remarks below.)
AddToRecentFiles - true to add the document to the list of recently used files on the File menu. The default is true.
WritePassword - A password string for saving changes to the document. (See Remarks below.)
ReadOnlyRecommended - true to have Microsoft Office Word suggest read-only status whenever the document is opened. The default is false.
EmbedTrueTypeFonts - true to save TrueType fonts with the document. If omitted, the EmbedTrueTypeFonts argument assumes the value of the EmbedTrueTypeFonts property.
SaveNativePictureFormat - If graphics were imported from another platform (for example, Macintosh), true to save only the Windows version of the imported graphics.
SaveFormsData - true to save the data entered by a user in a form as a data record.
SaveAsAOCELetter - If the document has an attached mailer, true to save the document as an AOCE letter (the mailer is saved).
Encoding - MsoEncoding. The code page, or character set, to use for documents saved as encoded text files. The default is the system code page.
InsertLineBreaks - If the document is saved as a text file, true to insert line breaks at the end of each line of text.
AllowSubstitutions - 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 - The way Word marks the line and paragraph breaks in documents saved as text files. Can be any WdLineEndingType value.
AddBiDiMarks - true adds control characters to the output file to preserve bi-directional layout of the text in the original document.



Document.SaveFormat




Has the Document Changed

The objDocument.Saved property equals True if the document has not changed since it was last saved
This example saves the active document if it's changed since it was last saved.

If (objDocument.Saved = False) Then 
   objDocument.Save
End If


Saving for the first time

ActiveDocument.SaveAs FileName:="C:\Temp\document.doc" 

If you do not specify the folder path then the document is saved in the current folder.

ActiveDocument.SaveAs FileName:="document.doc" 

You should always specify the full folder path.



Saving all Open Documents

You can quickly close all the open documents without prompting to save the changes

Documents.Save NoPrompt:=True, _ 
               OriginalFormat:=wdOriginalFormat.wdOriginalDocumentFormat


Checking Properties

You can check to see which properties where set for an activedocument

If (ActiveDocument.EmbedTrueTypeFonts = True) Then 
End If


© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext