Delphi操作word时需要把书签删除,书签所包含的内容也一并删除,怎么做到?

解决方案 »

  1.   

    我来啦!!!
    var
      FWordApp: Variant;
      i: integer;
    begin
        try
          FWordApp:=CreateOleObject('Word.Application');
          FWordApp.Visible:=True;
          FWordApp.Documents.Open('D:\Test.doc');
          for i:= FWordApp.ActiveDocument.BookMarks.count downto 1 do
            FWordApp.ActiveDocument.BookMarks.item(i).delete;
        except
          MessageDlg('出错',mtError,[mbOK],0);
          Application.ProcessMessages;
          FWordApp.Quit;
          Application.Terminate;
        end;
    end;
      

  2.   

    我又来啦!!! 这次是连那段内容的!!!
        try
          FWordApp:=CreateOleObject('Word.Application');
          FWordApp.Visible:=True;
          FWordApp.Documents.Open('D:\Test.doc');
          for i:= FWordApp.ActiveDocument.BookMarks.count downto 1 do
            FWordApp.ActiveDocument.BookMarks.item(i).Range.delete;
        except
          FWordApp.DisplayAlerts:=false;
          FWordApp.Quit;
          Application.Terminate;
        end;
      

  3.   

    好像需要些参数,虽然是可选,但Delphi里好像必须写,那我只好自己定义了一下,搞定了,多谢!
    expression.Delete(Unit, Count)Unit   Variant 类型,可选。所需删除的折叠区域或选定内容的单位。可为以下两种 WdUnits 常量之一:wdCharacter 或 wdWord。默认值为 wdCharacter。Count   Variant 类型,可选。所需删除的单元的数目。折叠某区域或选定内容并将此参数设置为正数,可删除该区域或选定内容之后的单元。折叠某区域或选定内容并将此参数设置为负数,可删除该区域或选定内容之前的单元。