Function Reference


_Word_DocSaveAs

Saves the specified Word document with a new name or format

#include <Word.au3>
_Word_DocSaveAs ( $oDoc [, $sFileName = Default [, $iFileFormat = $WdFormatDocument [, $bReadOnlyRecommended = False [, $bAddToRecentFiles = True [, $sPassword = "" [, $sWritePassword = ""]]]]]] )

Parameters

$oDoc Word document object
$sFileName [optional] The full path name for the document (default = Current folder and current file name if the document has been saved before).
If the document has never been saved before, the default name is used and the document is saved in the MyDocuments folder e.g. "@MyDocumentsDir\Doc1.doc".
$iFileFormat [optional] The format in which the document is saved.
Can be any WdSaveFormat constant (default = $WdFormatDocument)
$bReadOnlyRecommended [optional] True to have Word suggest read-only status whenever the document is opened (default = False)
$bAddToRecentFiles [optional] True to add the document to the list of recently used files (default = True)
$sPassword [optional] A password string for opening the document (default = "")
$sWritePassword [optional] A password string for saving changes to the document (default = "")

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 - $oDoc is not an object
2 - Error occurred when saving the specified document. @extended is set to the COM error code

Remarks

If a document with the specified file name already exists, the document is overwritten without the user being prompted first.

Related

_Word_DocSave

Example

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <Word.au3>

; Copy \Extras\Test.doc to @TempDir
If FileCopy(@ScriptDir & "\Extras\Test.doc", @TempDir & "\_Word_Test.doc", $FC_OVERWRITE) = 0 Then Exit MsgBox($MB_SYSTEMMODAL, _
                "Word UDF: _Word_DocSaveAs Example", "Couldn't copy '.\Extras\Test.doc' as '_Word_Test.doc' to the @TempDir directory.")
; Create application object
Local $oWord = _Word_Create()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
                "Error creating a new Word application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Open the test document
Local $oDoc = _Word_DocOpen($oWord, @TempDir & "\_Word_Test.doc")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
                "Error opening '_Word_Test.doc'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; Save the document as _Word_Test2.doc
; Insert text at the beginning
Local $oRange = _Word_DocRangeSet($oDoc, -1)
$oRange.Text = "Bold text at the beginning. "
$oRange.Bold = True
; Save document
_Word_DocSaveAs($oDoc, @TempDir & "\_Word_Test2.doc")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", _
                "Error saving the Word document." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocSaveAs Example", "Document successfully saved as '" & _
                @TempDir & "\_Word_Test2.doc'.")