...check if Word, Excel, Access, Outlook, Powerpoint is running?

Author: Thomas Stutz

Category: Objects/ActiveX

uses
  
ComObj, ActiveX;

function IsObjectActive(ClassName: string): Boolean;
var
  
ClassID: TCLSID;
  Unknown: IUnknown;
begin
  try
    
ClassID := ProgIDToClassID(ClassName);
    Result  := GetActiveObject(ClassID, nil, Unknown) = S_OK;
  except
    
// raise;
    
Result := False;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if 
IsObjectActive('Word.Application') then ShowMessage('Word is running !');
  if IsObjectActive('Excel.Application') then ShowMessage('Excel is running !');
  if IsObjectActive('Outlook.Application') then ShowMessage('Outlook is running !');
  if IsObjectActive('Access.Application') then ShowMessage('Access is running !');
  if IsObjectActive('Powerpoint.Application') then ShowMessage('Powerpoint is running !');
end;

 

printed from
www.swissdelphicenter.ch
developers knowledge base