Einzelnen Beitrag anzeigen

WizoHulk

Registriert seit: 25. Jun 2010
198 Beiträge
 
Delphi 5 Enterprise
 
#7

AW: OLE - Excel schließt sich nach Create

  Alt 2. Mai 2011, 15:03
habe die Variablen jetzt im Privat bereich deklariert.
jetzt wirft er mir aber eine exception wenn ich excel oder word createn will.

hier mal mein code
Delphi-Quellcode:
//********************************************************************************************************
// Microsoft OLE *}
{*    Anfang     *}
type
  TOffice = class(TObject)
  private
 // Excel : OleVariant;
// Word : OleVariant;
  public
    Excel : OleVariant;
    Word : OleVariant;
    constructor Create;
    destructor destroy;override;
    procedure OeffneWord(NeuesDokument: Boolean = False);
    procedure OeffneExcel(NeueTabelle : Boolean = False);
  end;

{*     Ende      *}

implementation
//*********************************************************************************************************
// MICROSOFT
// *Anfang*
//*********************************************************************************************************

constructor TOffice.Create;
begin
// mach was
end;

destructor TOffice.destroy;
begin
//destroy
end;

procedure TOffice.OeffneExcel(NeueTabelle : Boolean = False);
const
  ERROR_MSG : string = 'Microsoft Excel kann nicht starten!';

begin
  try
    Excel := GetActiveOleObject('Excel.Application');
    Excel.Windowstate := wsNormal
  except
    {* Ist keine Vorhanden wird neu erstellt *}
    try
      screen.Cursor := crHourGlass; //SandUhr Aktiv
      Excel := CreateOleObject('Excel.Application'); //Instanz wird erstellt
      Excel.Visible := True; //Ohne Worte
      if NeueTabelle then
        Excel.Workbooks.Add; //ein Tabsheet wird hinzugefügt
      screen.Cursor :=crDefault; //Sanduhr Deaktiv
    except
      ShowMessage(ERROR_MSG);
    end;
  end;
  screen.cursor:=crDefault;
end;

procedure TOffice.OeffneWord(NeuesDokument: Boolean = False);
var
  Word : OleVariant;
begin
 try
   {* Prüfe ob instanz vorhanden ist *}
   Word := GetActiveOleObject('Word.Application');
   Word.WindowState := wsNormal;
 except
   try
     screen.Cursor := crHourGlass;
     Word := CreateOleObject('Word.Application');
     Word.Visible := True;
     if NeuesDokument then
       Word.Documents.Add;
   except
     ShowMessage('Microsoft Word kann nicht starten.');
   end;
 end;
 screen.cursor:=crDefault;

end;

//*********************************************************************************************************
// MICROSOFT
// *Ende*
//*********************************************************************************************************
  Mit Zitat antworten Zitat