这是我录制的宏用来更新目录的
With ActiveDocument
        .TablesOfContents(1).Delete
        .TablesOfContents.Add Range:=Selection.Range, RightAlignPageNumbers:= _
            True, UseHeadingStyles:=True, UpperHeadingLevel:=1, _
            LowerHeadingLevel:=3, IncludePageNumbers:=True, AddedStyles:=""
        .TablesOfContents(1).TabLeader = wdTabLeaderDots
    End With我把它改写成delphi代码
  AppWord.Activedocument.TablesOfContents.Delete;
  AppWord.Activedocument.TablesOfContents.RightAlignPageNumbers:=True;
  AppWord.Activedocument.TablesOfContents.UseHeadingStyles:=True;
  AppWord.Activedocument.TablesOfContents.UpperHeadingLevel:=1;
  AppWord.Activedocument.TablesOfContents.LowerHeadingLevel:=3;
  AppWord.Activedocument.TablesOfContents.IncludePageNumbers:=True;
  AppWord.Activedocument.TablesOfContents(1).TabLeader := wdTabLeaderDots;
  AppWord.Activedocument.TablesOfContents.format:=wdIndexIndent;结果它说我没有这个TablesOfContents方法,怎么回事难道我写错了
同志们,调试好了再告诉我正确的。

解决方案 »

  1.   

    这样:
    AppWord.ActiveDocument.TablesOfContents.Item(0).Delete;
    AppWord.ActiveDocument.TablesOfContents.Item(0).RightAlignPageNumbers:=true;
    ......Delphi包装过的,和VBA有差别。
      

  2.   

    同意楼上,录制的宏使用的是vb,要用delphi的代码检查一下
      

  3.   

    AppWord.Activedocument.TablesOfContents.item(1).delete;
      docrange:=AppWord.Activedocument.range;
      AppWord.Activedocument.TablesOfContents.item(1).add(Range:=docrange);
    我现在改成这样
    结果最后一句执行错误,说集合成员不存在
      

  4.   

    .insert
    我记得它有一个insert的方法可以插入空行,
    你找一个,试一试,一定能行的,
    我原来做的那个程序我找不到了,
    所以没有办法给你贴源码!