![]() |
Excel offen und gesuchtes Workbook offen????
Hallo, ich suche eine Möglichkeit wie ich in Delphi6 prüfen kann ob Excel schon läuft und besonders ob das gesuchte Workbook schon aktiv ist. Wäre toll, falls mir jemand helfen könnte :oops:
|
Re: Excel offen und gesuchtes Workbook offen????
Hi,
ob Excel läuft, also, offen ist ;-), kann du mit dieser Funktion prüfen:
Delphi-Quellcode:
Ich hoffe, ich konnte dir ein bissl helfen!
function ExeFileIsRunning(ExeFile: string): boolean;
var H:word; begin H := CreateFile(PChar(ExeFile), GENERIC_READ, 0, nil, OPEN_EXISTING, 0, 0); Result := (H >= 65535); CloseHandle(H); end; Zu den Workbooks, schau doch mal in die Kategorie "Server" in Delphi und ab siehst du einige Excel-Server. Doch passe auf. Wenn du diese verwendest, muss der PC, auf dem dein Prog ausgeführt wird, mit der Excel-Version übereinstimmen, für die auch die verwendete Server-Komponente ist. Bye DJ-SPM |
Re: Excel offen und gesuchtes Workbook offen????
Danke, dank den Code-Library hab ich noch ne andere Möglichkeit gefund. Bleibt aber immer noch das Problem mit dem offenen Workbook. Aber hier werd ich deinen Rat aufjedenfall befolgen.
|
Re: Excel offen und gesuchtes Workbook offen????
hi
welche möglichkeit hast du denn noch gefunden ? weil ich dasselbe in meinem programm abfragen möchte und such ne elegante lösung :) thx 4 help mfg stoni |
Re: Excel offen und gesuchtes Workbook offen????
hi, ich habs jetzt wie folgt gelöst:
function TFrorm1.IsProgActive(sClassName: String): Boolean; var ClassID: TCLSID; Unknown: IUnknown; begin try ClassID := ProgIDToClassID(sClassName); Result := GetActiveObject(ClassID, nil, Unknown) = S_OK; except Result := False; end; end; procedure TForm1.Butto1Click(Sender: TObject); const xlCellTypeLastCell = $0000000B; var WorkAkt,AppAkt:Boolean; MessPfad: String; begin Messpfad:='C:/2004_09_28_Messdaten.xls'; try AppAkt:=false; WorkAkt:=true; try //Abfrage ob Excel aktiv, dann if IsProgActive('Excel.Application') then begin TExcelApplication.ConnectKind := ckNewInstance instead of ckRunningOrNew; AppAkt:=true; ExcelApplication1 := TExcelapplication.Create(nil); ExcelApplication1.ConnectKind := ckRunningOrNew; ExcelApplication1.Connect; ExcelApplication1.Visible[GetUserDefaultLCID]:=true; ExcelApplication1.UserControl:=True; //Falls Excel aktiv, auch mein Workbook??? if Messpfad <> ExcelApplication1.ActiveWorkbook.Path[GetUserDefaultLCID]+'\'+ExcelApplication1.ActiveWorkbook.Name then begin ExcelApplication1.Workbooks.Open (Pfad,False,False,EmptyParam,'',False,False,EmptyP aram,EmptyParam,false,false,EmptyParam,false,0); WorkAkt:=false; end; ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveW orkBook); end else begin //Wenn nicht offen, dann aktiviere Excel und standartweg einleiten WorkAkt:=false; ExcelApplication1 := TExcelapplication.Create(nil); ExcelApplication1.ConnectKind := ckRunningOrNew; ExcelApplication1.Connect; ExcelApplication1.Visible[GetUserDefaultLCID]:=true; ExcelApplication1.UserControl:=True; ExcelApplication1.Workbooks.Open(Pfad,False,False, EmptyParam,'',False,False,EmptyParam,EmptyParam,fa lse,false,EmptyParam,false,0); // Workbook verbinden ExcelWorkbook1.ConnectTo(ExcelApplication1.ActiveW orkBook); end; // Woorksheet verbinden und aktivieren ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets.It em['Peltier'] as _Worksheet); ExcelWorksheet1.Activate; //Und jetzt Workbook und Worksheet auslesen... Ich hoff ich kann damit etwas helfen. :idea: Gruß Daniel P.S.: Falls noch jemand einen besseren Weg weiß, ich bin immer offen... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:28 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz