# Function Reference

# _Excel_BookSaveAs

Saves the specified workbook with a new filename and/or type

#include <Excel.au3>
_Excel_BookSaveAs ( $oWorkbook, $sFilePath [, $iFormat = $xlWorkbookDefault [, $bOverWrite = False [, $sPassword = Default [, $sWritePassword = Default [, $bReadOnlyRecommended = False]]]]] )

## Parameters

$oWorkbook | Workbook object to be saved
$sFilePath | Path and filename of the file to be saved to
$iFormat | [optional] Excel writeable filetype. Can be any value of the XlFileFormat enumeration
$bOverWrite | [optional] True overwrites an already existing file (default = False)
$sPassword | [optional] The string password to protect the file with. If set to keyword Default no password will be used (default = keyword Default)
$sWritePassword | [optional] The string write-access password to protect the file with. If set to keyword Default no password will be used (default = keyword Default)
$bReadOnlyRecommended | [optional] True displays a message when the file is opened, recommending that the file be opened as read-only (default = False)

## Return Value

Success: | 1.
Failure: | 0 and sets @error.
@error: | 1 - $oWorkbook is not an object 2 - $iFormat is not a number 3 - File exists, overwrite flag not set 4 - File exists but could not be deleted 5 - Error occurred when saving the workbook. @extended is set to the COM error code returned by the SaveAs method.

## Remarks

Starting with Excel 2007 you have to provide both the $iFormat parameter and the correct file extension in $sFilePath.
E.g. $iFormat = $xlExcel8 and extension = "xlsx" will return an error.
Please see the XlFileFormat enumeration in ExcelConstants.au3 for possible values.

## Related

_Excel_BookSave

## Example

    #include "Extras\HelpFileInternals.au3"

    #include <Excel.au3>
    #include <MsgBoxConstants.au3>

    ; Create application object and open an example workbook
    Local $oExcel = _Excel_Open()
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    Local $oWorkbook = _Excel_BookOpen($oExcel, _Extras_PathFull("_Excel1.xls"))
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example", "Error opening workbook '" & _Extras_PathFull("_Excel1.xls'.") & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_Close($oExcel)
        Exit
    EndIf

    ; Save the workbook (xls) in another format (html) to another directory and
    ; overwrite an existing version
    Local $sWorkbook = @TempDir & "\_Excel1.html"
    _Excel_BookSaveAs($oWorkbook, $sWorkbook, $xlHtml, True)
    If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Error saving workbook to '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookSaveAs Example 1", "Workbook successfully saved as '" & $sWorkbook & "'.")
    ShellExecute($sWorkbook)