At the end of our a Word2010 document we've a numbered list of 6 items. We would like to add a text, say, End of Document
at the end of that document using VBA
. But when I try the following code it always add a new list item (item 7) to the list with that text as shown in image below. NOTE : We don't have control over the document. So the last line of the document is always item number 6 of the list and when a user runs VBA code the code is supposed to add last line at the end of the document as End of document.
And this line should not be the last item of the list.:
Sub test()
Dim oList As List
Set oList = ActiveDocument.Lists(1)
oList.Range.InsertParagraphAfter
oDoc.Content.InsertAfter "End of Document";
End Sub
Snapshot of the list at the End of a document :
Since you want to insert at the end of the document, you dont even need to find the list, this should do:
With ActiveDocument.Content
.InsertParagraphAfter
With .Paragraphs(.Paragraphs.Count).Range
.InsertAfter "End of Document"
.Style = wdStyleNormal
End With
End With
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.