procedure TMainFrm.Button1Click(Sender: TObject);
var
  WordApplication1: TWordApplication;
  Filename,AddToRecentFiles,Visible:olevariant;
begin
   {联接WORD}  
   wordapplication1.connect;
   wordapplication1.visible := true; 
   FileName := 'D:\workdir\文档\项目经理\Proj1.doc';
   AddToRecentFiles:='';
   Visible := false;
WordApplication1.Documents.Add                                                       (FileName,Visible,AddToRecentFiles,Visible);
end以上的代码,最后一句出现"类型不匹配的错误"? 

解决方案 »

  1.   

    //取得Word文件的数据
    procedure getWordStr;
    var WordApp: TWordApplication;
        WordDoc: TWordDocument;
        DocInx,oFileName,CfCversions,oReadOnly,AddToRctFiles,PswDocument,
        PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat: OleVariant;
        i,iRow,iCol:integer;
        myCell:Cell;
        myRow:Row;
    begin
      memo1.Lines.Clear ;    // ===== 创建对象 =====
        if not Assigned(WordApp) then                          
        begin
          WordApp:= TWordApplication.Create(nil);
          WordApp.Visible := false;
        end;
        if not Assigned(WordDoc) then
          WordDoc:= TWordDocument.Create(nil);
      try
        DocInx:=1;
        oFileName := 'd:\test.doc';
        oReadOnly:=true;
        CfCversions := EmptyParam;
        AddToRctFiles:= EmptyParam;
        PswDocument:= EmptyParam;
        PswTemplate:= EmptyParam;
        oRevert:= EmptyParam;
        WPswDocument:= EmptyParam;
        WPswTemplate:= EmptyParam;
        oFormat:= EmptyParam;     
        // ===== 打开文件 =====                         
        WordApp.Documents.open(oFileName,CfCversions,oReadOnly,AddToRctFiles,
           PswDocument,PswTemplate,oRevert,WPswDocument,WPswTemplate,oFormat);
        // ===== 关联文件 =====
        WordDoc.ConnectTo(WordApp.Documents.Item(DocInx)); 
        //方法(1): 取整个文本的字符内容,包含表格
        s := WordDoc.Range.text;      //方法(2): 取 1 -- 4 位的字符 ,包含表格 
        myRange:=WordDoc.Range;
        myRange.Start:=0;
        myRange.End_ :=4;  finally
        if Assigned(WordDoc) then              // ===== 关闭文件 =====
        begin
          WordDoc.Close;
          WordDoc.Disconnect;
          WordDoc.Destroy;
          WordDoc := nil;
        end;
        if Assigned(WordApp) then              // ===== 关闭Word =====
        begin
          WordApp.Quit;
          WordApp.Disconnect;
          WordApp.Destroy;
          WordApp := nil;
        end;
      end;
    end;
      

  2.   

    这个对不上,我想实现, 第一步新建一个WORD文档, 然后把TDBMemo里面的内容导入WORD文档中???
      

  3.   

    应用于 Documents 对象的 Add 方法。返回一个 Document 对象,该对象代表添加至打开文档集合中的新建空文档。
    expression.Add(Template, NewTemplate, DocumentType, Visible)expression   必需。该表达式返回一个 Documents 对象。Template  Variant 类型,可选。新文档使用的模板名。如果忽略此参数,则使用 Normal 模板。NewTemplate  Variant 类型,可选。如果为 True,则将文档作为模板打开。默认值是 False。DocumentType  Variant 类型,可选。可以是下列 WdNewDocumentType 常量之一:wdNewBlankDocument、wdNewEmailMessage、wdNewFrameset 或 wdNewWebPage。默认值为 wdNewBlankDocument。Visible  Variant 类型,可选。如果为 True,将在可见窗口打开文档;如果为 False,Microsoft Word 会打开此文档并将文档窗口的 Visible 属性设为 False。该属性的默认值为 True。
    ==================================================
    取自word帮助文档,再好好研究研究把~~~
      

  4.   

    Template: 使用模板的名称,
    NewTemplate: 新建文档的类型,True表示为模板,False表示为文档
    DocumentType: 文档类型,默认为空白文档
    Visible: 窗口是否可见WordApp.Documents.Add(fileName, newTemplate, docType, isVisible)
      

  5.   

    USES comobj;var
      WordApp,WordDoc,WordTable:OleVariant;
    begin
      WordApp:=CreateOleObject('Word.Application');
      WordApp.Visible:=True;
      WordDoc:=WordApp.Documents.Add;
      WordApp.Selection.Range.Text :='HELLO';
      WordDoc.saveas('c:\a.doc');
      wordapp.quit;
    end;
      

  6.   

    谢了,游民:如何得到当然程序的目录?WordDoc.saveas(getname);
      

  7.   

    谢了,游民:如何得到当然程序的目录?WordDoc.saveas(getname);
      

  8.   

    WordDoc.saveas(GetCurrentDir+'\'+getname)