Search notes:

Word Object Model: document.saveAs2

document.saveAs2 is used to save a document, typically with a different name or in a different Word format.
In order to just save the document (like ctrl+s), The document.save method is a more straight forward way.

Parameters

All parameters of document.saveAs2 are optional
Parameter name default value
fileName ?
fileFormat Any wdSaveFormat constants (see below) ?
lockComments false
password ?
addToRecentFiles true
writePassword ?
readOnlyRecommended false
embedTrueTypeFonts value of embedTrueTypeFonts
saveNativePictureFormat ?
saveFormsData ?
saveAsAOCELetter ?
encoding ?
insertLineBreaks ?
allowSubstitutions false
lineEnding wdCRLF
addBiDiMarks ?
compatibilityMode ?

wdSaveFormat constants

wdFormatDocument 0 Microsoft Office Word 97 - 2003 binary file format.
wdFormatDOSText 4 Microsoft DOS text format.
wdFormatDOSTextLineBreaks 5 Microsoft DOS text with line breaks preserved.
wdFormatEncodedText 7 Encoded text format.
wdFormatFilteredHTML 10 Filtered HTML format.
wdFormatFlatXML 19 Open XML file format saved as a single XML file. (extension .docx)
wdFormatFlatXMLMacroEnabled 20 Open XML file format with macros enabled saved as a single XML file. (extension .docm)
wdFormatFlatXMLTemplate 21 Open XML template format saved as a XML single file.
wdFormatFlatXMLTemplateMacroEnabled 22 Open XML template format with macros enabled saved as a single XML file.
wdFormatOpenDocumentText 23 OpenDocument Text format.
wdFormatHTML 8 Standard HTML format.
wdFormatRTF 6 Rich text format (RTF).
wdFormatStrictOpenXMLDocument 24 Strict Open XML document format.
wdFormatTemplate 1 Word template format.
wdFormatText 2 Microsoft Windows text format.
wdFormatTextLineBreaks 3 Windows text format with line breaks preserved.
wdFormatUnicodeText 7 Unicode text format.
wdFormatWebArchive 9 Web archive format.
wdFormatXML 11 Extensible Markup Language (XML) format.
wdFormatDocument97 0 Microsoft Word 97 document format.
wdFormatDocumentDefault 16 Word default document file format. For Word, this is the DOCX format.
wdFormatPDF 17 PDF format.
wdFormatTemplate97 1 Word 97 template format.
wdFormatXMLDocument 12 XML document format.
wdFormatXMLDocumentMacroEnabled 13 XML document format with macros enabled.
wdFormatXMLTemplate 14 XML template format.
wdFormatXMLTemplateMacroEnabled 15 XML template format with macros enabled.
wdFormatXPS 18 XPS format.

Save document as PDF

The following simple example saves a MS Word document in the PDF format in the same directory where the Word document already is located. The name of the PDF file will be doc.pdf. If doc.pdf already exists, it will be overwritten.
activeDocument.saveAs2                  _
   activeDocument.path & "\doc.pdf"   , _
   fileFormat         := wdFormatPdf  , _
   addToRecentFiles   := false        , _
   embedTrueTypeFonts := true

See also

The document object

Index