2016-12-27 106 views
0

在我们的Word2010文档的末尾,我们有一个包含6个项目的编号列表。我们希望在文档末尾使用VBA添加一个文本,例如End of Document。但是,当我尝试下面的代码时,它总是添加一个新的列表项目(项目7)到该文本列表中,如下图所示。 注意:我们无法控制文档。因此,文档的最后一行始终是列表中的项目编号6,并且当用户运行VBA代码时,代码应该在文档末尾添加最后一行作为End of document.并且此行不应该是列表中的最后一项:在文档的最终名单WORD VBA插入列表后插入文本

Sub test() 

Dim oList As List 

Set oList = ActiveDocument.Lists(1) 
oList.Range.InsertParagraphAfter 
oDoc.Content.InsertAfter "End of Document"; 

End Sub 

快照:

enter image description here

回答

0

既然你想在文件末尾插入,你甚至需要找到列表中,应该这样做:

With ActiveDocument.Content 
    .InsertParagraphAfter 
    With .Paragraphs(.Paragraphs.Count).Range 
     .InsertAfter "End of Document" 
     .Style = wdStyleNormal 
    End With 
End With