if FileExists('Word2000.exe') 
then MessageBox(Handle, PChar('文件存在'), '', MB_ICONINFORMATION)
else MessageBox(Handle, PChar('文件不存在'), '', MB_ICONINOFORMATION)

解决方案 »

  1.   

    如果仅仅是监测word2000是否存在,可以用COM调用判断!
      

  2.   

    阿春呀!这样做只能测当前目录下的文件!但用户机器上的程序目录是不一样的如何监测程序存在!
    if FileExists('Word2000.exe') 
    then MessageBox(Handle, PChar('文件存在'), '', MB_ICONINFORMATION)
    else MessageBox(Handle, PChar('文件不存在'), '', MB_ICONINOFORMATION) 
      

  3.   

    uses ComObj;
    var
      V: Variant;
    begin
      try
        //检索Word并运行
        V := CreateOleObject('Word.Application'); 
        V.Visible := True;
      except 
        ShowMessage('你的系统未安装Word或Word不能正常运行');
      end;
    end;
      

  4.   

    WuHeHai(河海)的解答不是挺好吗? 
      

  5.   

    你可以在整个机器上查找文件,
    shellexcute(,find,,,,,,);
      

  6.   

    河海老兄!首先谢谢你解决了我的问题,能不能改调用excel呀!我试了不行呀...
      

  7.   

    算了,这个问题很简单的,自己搜索硬盘就知道了,如果要调用Office里面的程序,用Com方法就可以了。
    Word:Word.application
    Excel:Excel.Application
    ....
    就是WuHeHai的方法。
      

  8.   

    为什么在调用EXCEL时出现画面一闪而过呢?
      

  9.   

    var
      V:Variant;
    begin
      try
        //获取当前运行的Word
        v:=GetActiveOleObject('Word.Basic');
      except
        //若当前没有运行的Word,则创建
        v:=CreateOleObject('Word.Basic');
      end;
    end;对于非COM的一般程序则可以参照《电脑爱好者》13期做法(如:截取QQ的登陆框等)。
      

  10.   

    河海老兄不知在线吗?我想将这个程序能通用一点,其它都正常,但在调用EXCEL时出现画面一闪而过为什么呢?  谢谢解答!! 
      

  11.   


    Excel使用:GetActiveOleObject('Excel.Application');和CreateOleObject('Excel.Application');
      

  12.   

    var  XLApp:Variant;XLApp:=CreateOleObject('Excel.Application');
    XLApp.Visible:=True;
      

  13.   


    给你一个完全版啦:
    unit Main;
    {
      Main.pas
      Copyright (c) 1997 by Charlie Calvert
      Creating data and a chart in Excel and copying both to Word.
    }interfaceuses
      Windows, Messages, SysUtils,
      Classes, Graphics, Controls,
      Forms, Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        SendMailBtn: TButton;
        procedure Button1Click(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure SendMailBtnClick(Sender: TObject);
      private
        XLApp: Variant;
        WordApp: Variant;
      public
        procedure HandleData;
        procedure ChartData;
        procedure CopyData;
        procedure CopyChartToWord;
        procedure CopyCellsToWord;
      end;var
      Form1: TForm1;implementationuses
      ComObj, XLConst, WordConst,
      ActiveX;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    begin
      XLApp := CreateOleObject('Excel.Application');
      XLApp.Visible := True;
      XLApp.Workbooks.Add[XLWBatWorksheet];
      XLApp.Workbooks[1].Worksheets[1].Name := 'Delphi Data';
      HandleData;
      ChartData;
      CopyData;
      SendMailBtn.Enabled := True;
    end;procedure TForm1.HandleData;
    var
      Sheet: Variant;
      i: Integer;
    begin
      Sheet := XLApp.Workbooks[1].Worksheets['Delphi Data'];
      for i := 1 to 10 do
        Sheet.Cells[i, 1] := i;
    end;procedure TForm1.ChartData;
    var
      ARange: Variant;
      Sheets: Variant;
    begin
      XLApp.Workbooks[1].Sheets.Add(,,1,xlChart);
      Sheets := XLApp.Sheets;
      ARange := Sheets.Item['Delphi Data'].Range['A1:A10'];
      Sheets.Item['Chart1'].SeriesCollection.Item[1].Values := ARange;
      Sheets.Item['Chart1'].ChartType := xl3DPie;
      Sheets.Item['Chart1'].SeriesCollection.Item[1].HasDataLabels := True;  XLApp.Workbooks[1].Sheets.Add(,,1,xlChart);
      Sheets.Item['Chart2'].SeriesCollection.Item[1].Values := ARange;
      Sheets.Item['Chart2'].SeriesCollection.Add(ARange);
      Sheets.Item['Chart2'].SeriesCollection.NewSeries;
      Sheets.Item['Chart2'].SeriesCollection.Item[3].Values :=
        VarArrayOf([1,2,3,4,5, 6,7,8,9,10]);
      Sheets.Item['Chart2'].ChartType := xl3DColumn;
    end;procedure TForm1.CopyData;
    var
      Sheets: Variant;
    begin
      SetFocus;
      
      Sheets := XLApp.Sheets;  Sheets.Item['Delphi Data'].Activate;
      Sheets.Item['Delphi Data'].Range['A1:A10'].Select;
      Sheets.Item['Delphi Data'].UsedRange.Copy;  CopyCellsToWord;  Sheets.Item['Chart1'].Select;
      XLApp.Selection.Copy;  CopyChartToWord;
    end;procedure TForm1.CopyChartToWord;
    var
      Range: Variant;
      i, NumPars: Integer;
    begin
      NumPars := WordApp.Documents.Item(1).Paragraphs.Count;  Range := WordApp.Documents.Item(1).Range(
        WordApp.Documents.Item(1).Paragraphs.Item(NumPars).Range.Start,
        WordApp.Documents.Item(1).Paragraphs.Item(NumPars).Range.End);
      Range.Text := 'This is graph: ';  for i := 1 to 3 do WordApp.Documents.Item(1).Paragraphs.Add;  Range := WordApp.Documents.Item(1).Range(
        WordApp.Documents.Item(1).Paragraphs.Item(NumPars + 1).Range.Start,
        WordApp.Documents.Item(1).Paragraphs.Item(NumPars + 1).Range.End);  Range.Paste; //Special(,,,,wdPasteOleObject);  
    end;procedure TForm1.CopyCellsToWord;
    var
      Range: Variant;
      i: Integer;
    begin
      WordApp := CreateOleObject('Word.Application');
      WordApp.Visible := True;
      WordApp.Documents.Add;
      Range := WordApp.Documents.Item(1).Range;
      Range.Text := 'This is a column from a spreadsheet: ';
      for i := 1 to 3 do WordApp.Documents.Item(1).Paragraphs.Add;
      Range := WordApp.Documents.Item(1).Range(
        WordApp.Documents.Item(1).Paragraphs.Item(3).Range.Start);
      Range.Paste;
      for i := 1 to 3 do WordApp.Documents.Item(1).Paragraphs.Add;
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      if not VarIsEmpty(XLApp) then begin
        XLApp.DisplayAlerts := False;  // Discard unsaved files....
        XLApp.Quit;
      end;  if not VarIsEmpty(WordApp)then begin
        WordApp.Documents.Item(1).Close(wdDoNotSaveChanges);
        WordApp.Quit;
      end;
    end;procedure TForm1.SendMailBtnClick(Sender: TObject);
    begin
      WordApp.Documents.Item(1).SaveAs('c:\foo.doc');
      WordApp.Options.SendMailAttach := True;
      WordApp.Documents.Item(1).SendMail;
    end;end.