Function Reference


_Excel_BookOpen

Opens an existing workbook

#include <Excel.au3>
_Excel_BookOpen ( $oExcel, $sFilePath [, $bReadOnly = False [, $bVisible = True [, $sPassword = Default [, $sWritePassword = Default [, $bUpdateLinks = Default]]]]] )

Parameters

$oExcel Excel application object where you want to open the workbook
$sFilePath Path and filename of the file to be opened
$bReadOnly [optional] True opens the workbook as read-only (default = False)
$bVisible [optional] True specifies that the workbook window will be visible (default = True)
$sPassword [optional] The password that was used to read-protect the workbook, if any (default is none)
$sWritePassword [optional] The password that was used to write-protect the workbook, if any (default is none)
$bUpdateLinks [optional] Specifies the way external references (links) in the file are updated (default = keyword Default)
Valid values are:
    Default: Excel prompts the user to decide how to update links.
    0: Excel doesn't update links.
    3: Excel updates all links.

Return Value

Success: an workbook object. @extended is set to 1 if $bReadOnly = False but read-write access could not be granted. Please see the Remarks section for details.
Failure: 0 and sets @error.
@error: 1 - $oExcel is not an object or not an application object
2 - Specified $sFilePath does not exist
3 - Unable to open $sFilePath. @extended is set to the COM error code returned by the Open method

Remarks

When you set $bReadOnly = False but the document can't be opened read-write @extended is set to 1.
The Workbook was opened read-only because it has already been opened by another user/task or the file is set to read-only by the filesystem.
If you modify the workbook you need to use _Excel_BookSaveAs() to save it to another location or with another name.

When setting $bVisible = False when opening a Workbook make sure to set the Workbook to visible again before saving the Workbook.
Use $oExcel.Windows($oWorkbook.Name).Visible = True to make the Workbook visible again.
Else the Workbook will not be shown when you manually open it using Excel.
Most of the time this parameter is not needed. Using $bVisible = False in _Excel_Open is the preferred way.

If $bUpdateLinks is set to Default the user is only prompted if $bDisplayAlerts is set to True in function _Excel_Open.
If $bDisplayAlerts is set to False, Excel chooses the default response.

Related

_Excel_BookAttach, _Excel_BookClose, _Excel_BookNew, _Excel_BookOpenText

Example

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

; Create application object
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

; *****************************************************************************
; Open an existing workbook and return its object identifier.
; *****************************************************************************
Local $sWorkbook = @ScriptDir & "\Extras\_Excel1.xls"
Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Error opening '" & $sWorkbook & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example 1", "Workbook '" & $sWorkbook & "' has been opened successfully." & @CRLF & @CRLF & "Creation Date: " & $oWorkbook.BuiltinDocumentProperties("Creation Date").Value)