So kannst du prüfen ob
- Excel bereits mit deinem Workbook geöffnet ist
- Excel ohne das Workbook geöffnet ist
- Excel nicht geöffnet ist
Entsprechend erfolgt der Zugriff auf die Tabelle.
Global $myPath = "DEINE.xls"
[/autoit][autoit][/autoit][autoit]Global $fOpen = False, $oBook, $oExcel = ObjGet('', 'Excel.Application') ; Zugriff auf geöffnetes Excel
If @error Then
; == Excel ist nicht geöffnet, neues Excel-Objekt erstellen
_OpenXLS(0)
Else
; == in Excel geöffnete Workbooks auflisten
$oBook = $oExcel.WorkBooks
For $book In $oBook
If $book.Path & '\' & $book.Name = $myPath Then
;~ ConsoleWrite($book.Path & '\' & $book.Name & @CRLF)
$oBook($book.Name).Activate
$oExcel.Visible = 1 ; nur wenn Tabelle sichtbar sein soll
$book.Sheets(2).Select()
$fOpen = True
ExitLoop
EndIf
Next
EndIf
If Not $fOpen Then _OpenXLS($oExcel) ;
Func _OpenXLS($_oExcel)
If Not IsObj($_oExcel) Then $oExcel = ObjCreate("Excel.Application") ; Excel-Objekt erstellen
$oExcel.Visible = 1 ; 0=unsichtbar/ 1=sichtbar
$oBook = $oExcel.Workbooks.Open($myPath) ; Datei öffnen
$oBook.Sheets(2).Select()
EndFunc