It gives me "Value = 0" (but yes it opens excel window, but not specific file).
#include <Excel.au3>
Func _Excel_BookOpenEX($oExcel, $sFilePath, $bReadOnly = Default, $bVisible = Default, $sPassword = Default, $sWritePassword = Default, $bUpdateLinks = Default)
; Error handler, automatic cleanup at end of function
Local $oError = ObjEvent("AutoIt.Error", "__Excel_COMErrFunc")
#forceref $oError
If Not IsObj($oExcel) Or ObjName($oExcel, 1) <> "_Application" Then Return SetError(1, @error, 0)
If Not FileExists($sFilePath) Then Return SetError(2, 0, 0)
If $bReadOnly = Default Then $bReadOnly = False
If $bVisible = Default Then $bVisible = True
Local $oWorkbook = $oExcel.Workbooks.Open($sFilePath, $bUpdateLinks, $bReadOnly, Default, $sPassword, $sWritePassword)
If @error Then Return SetError(3, @error, 0)
Local $oWindow = $oExcel.Windows($oWorkbook.Name) ; <== Modified
If IsObj($oWindow) Then $oWindow.Visible = $bVisible ; <== Modified
; If a read-write workbook was opened read-only then set @extended = 1
If $bReadOnly = False And $oWorkbook.Readonly = True Then Return SetError(0, 1, $oWorkbook)
Return $oWorkbook
EndFunc ;==>_Excel_BookOpen
Local $bOpenWorkBook = False, $oExcel = _Excel_Open()
Local $oWorkbook
Local $sFilePath = @ScriptDir & "trans.xlsx"
$oWorkbook = _Excel_BookAttach($sFilePath)
If @error Then
$oWorkbook = _Excel_BookOpenEX($oExcel, $sFilePath)
$bOpenWorkBook = True
EndIf
If $bOpenWorkBook Then
$sCell = _Excel_RangeRead($oWorkbook, Default, "A2") ;~ Workbook was opened so read cell A2
Else
$sCell = _Excel_RangeRead($oWorkbook, Default, $oExcel.ActiveCell.Address) ;~ Workbook was already open, read the active cell.
EndIf
MsgBox(4096, "Excel Cell Value", "Value = " & $sCell)