Opening PowerPoint

(early binding) Before you can use this method, you must have imported the type library (MSPpt8.olb for PowerPoint 97). One way of starting PowerPoint is to try the GetActiveObject call, to get a running instance of PowerPoint, but put a call to CoApplication.Create in an except clause. But except clauses are slow, and can cause problems within the IDE for people who like Break On Exceptions set to True. The following code removes the need for a try...except clause, by avoiding using OleCheck on GetActiveObject in the case when PowerPoint is not running.

uses Windows, ComObj, ActiveX, OfficePowerPoint_TLB;
 PowerPoint: _Application;
 AppWasRunning: boolean; // tells you if you can close PowerPoint when you've finished
 Unknown: IUnknown;
 Result: HResult;
 AppWasRunning := False;
 Result := GetActiveObject(CLASS_Application, nil, Unknown);
 if (Result = MK_E_UNAVAILABLE) then
  PowerPoint := CoApplication.Create
 else begin
  { make sure no other error occurred during GetActiveObject }
  OleCheck(Unknown.QueryInterface(_Application, PowerPoint));
  AppWasRunning := True;
 PowerPoint.Visible := TOleEnum(msoTrue);

Without using the type library
Automation is so much easier and faster using type libraries (early binding) that you should avoid managing without if at all possible. But if you really can't, here's how to get started:


 PowerPoint: Variant;



  PowerPoint := GetActiveOleObject('PowerPoint.Application');


  PowerPoint := CreateOleObject('PowerPoint.Application');


 PowerPoint.Visible := True;

Отправить комментарий

Антиспам проверка