各位,請幫幫忙,在delphi 7中如何打開word文檔?效果等同於雙擊打開這個word文檔。能提供一點代碼嗎?

解决方案 »

  1.   

    procedure   TForm1.Button1Click(Sender:   Tobject);   
      var   MSWord:   Variant;   
      begin   
      MSWord   :=   CreateOLEObject('Word.Application');//连接Word   
      MSWord.Documents.Open(FileName:='d:\test.doc',   ReadOnly:=True);//打开外部Word文档   
      MSWord.Visible   :=   1;//是否显示文件编辑   
      MSWord.ActiveDocument.Range(Start:=0,   End:=0);//开始改变的启止位置   
      MSWord.ActiveDocument.Range.InsertAfter(Text:='Title');//在Word中增加字符'Title'   
      MSWord.ActiveDocument.Range.InsertParagraphAfter;   
      MSWord.ActiveDocument.Range.Font.Name   :=   'Arial';//字体名称   
      MSWord.ActiveDocument.Range.Font.Size   :=   24;//字体大小   
      end;
      

  2.   

    很简单啦,楼上兄弟的代码就可以,不过别忘了引用ComObj哦!
    如下:
    implementation
     uses comobj;
    {$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
      var   OpenWord:   Variant;
      begin
      OpenWord:=   CreateOLEObject('Word.Application');//调用Word
      OpenWord.Documents.Open(FileName:='f:\test.doc');
      OpenWord.Visible :=1;
      end;
    end.