Function Reference


_ExcelBookSaveAs

Saves the active workbook of the specified Excel object with a new filename and/or type.

 #include <Excel.au3>
_ExcelBookSaveAs ( $oExcel, $sFilePath [, $sType = "xls" [, $fAlerts = 0 [, $fOverWrite = 0 [, $sPassword = "" [, $sWritePassword = "" [, $iAccessMode = 1 [, $iConflictResolution = 2]]]]]]] )

Parameters

$oExcel Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
$sFilePath Path and filename of the file to be read
$sType [optional] Excel writable filetype string = "xls|csv|txt|template|html", default "xls"
$fAlerts [optional] Flag for disabling/enabling Excel message alerts (0=disable, 1=enable)
$fOverWrite [optional] Flag for overwriting the file, if it already exists (0=no, 1=yes)
$sPassword [optional] The string password to protect the sheet with; if blank, no password will be used (default = blank)
$sWritePassword [optional] The string write-access password to protect the sheet with; if blank, no password will be used (default = blank)
$iAccessMode [optional] The document sharing mode to assign to the workbook:
$xlNoChange [optional] Leaves the sharing mode as it is (default) (numeric value = 1)
$xlExclusive [optional] Disables sharing on the workbook (numeric value = 3)
$xlShared [optional] Enable sharing on the workbook (numeric value = 2)
$iConflictResolution [optional] For shared documents, how to resolve sharing conflicts:
$xlUserResolution [optional] Pop up a dialog box asking the user how to resolve (numeric value = 1)
$xlLocalSessionChanges [optional] The local user's changes are always accepted (default) (numeric value = 2)
$xlOtherSessionChanges [optional] The local user's changes are always rejected (numeric value = 3)

Return Value

Success: 1.
Failure: 0 and sets the @error flag to non-zero.
@error: 1 - Specified object does not exist
2 - Invalid filetype string
3 - File exists, overwrite flag not set

Remarks

You can only SaveAs back to the same working path the workbook was originally opened from at this time
(not applicable to newly created, unsaved books).

Example

Example 1

; Open an existing workbook and returns its object identifier.  Then SaveAs the file under a new name, without any alerts.

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

Local $sFilePath1 = @ScriptDir & "\Test.xls" ;This file should already exist
Local $oExcel = _ExcelBookOpen($sFilePath1)

If @error = 1 Then
    MsgBox($MB_SYSTEMMODAL, "Error!", "Unable to Create the Excel Object")
    Exit
ElseIf @error = 2 Then
    MsgBox($MB_SYSTEMMODAL, "Error!", "File does not exist - Shame on you!")
    Exit
EndIf

_ExcelBookSaveAs($oExcel, @TempDir & "\SaveAsExample", "xls")
If Not @error Then MsgBox($MB_SYSTEMMODAL, "Success", "File was Saved!", 3)
_ExcelBookClose($oExcel, 1, 0) ;This method will save then Close the file, without any of the normal prompts, regardless of changes

Example 2

; Open an existing workbook and returns its object identifier.  Then SaveAs the file under a new name, without any alerts.
; Overwrite File if it exists, and protect the file using the password option. Then Open the File to show the Password Protection

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

Local $sFilePath1 = @ScriptDir & "\Test.xls" ;This file should already exist
Local $oExcel = _ExcelBookOpen($sFilePath1)

; Show any errors that might occur when Opening the File
If @error = 1 Then
    MsgBox($MB_SYSTEMMODAL, "Error!", "Unable to Create the Excel Object")
    Exit
ElseIf @error = 2 Then
    MsgBox($MB_SYSTEMMODAL, "Error!", "File does not exist - Shame on you!")
    Exit
EndIf

_ExcelBookSaveAs($oExcel, @TempDir & "\SaveAsExample2", "xls", 0, 1, "ReadOnly") ;Save the File as 'SaveAsExample2.xls"
If Not @error Then MsgBox($MB_SYSTEMMODAL, "Success", "File was Saved!", 3)
_ExcelBookClose($oExcel, 1, 0) ;This method will save then Close the file, without any of the normal prompts, regardless of changes

$oExcel = _ExcelBookOpen(@TempDir & "\SaveAsExample2.xls", 1, False) ;Open The previous File to show the password protection