![]() |
|
#1
|
|||
|
|||
![]() I found the code here below in "Microsoft Learn - Title: Range.InsertAfter method (Word)" But it seems to fail. Can someone explain? Thanks! Code:
Set doc = ActiveDocument Set rngRange = _ doc.Range(doc.Paragraphs(1).Start, _ doc.Paragraphs(1).End - 1) rngRange.InsertAfter _ " This is now the last sentence in paragraph one." |
#2
|
|||
|
|||
![]()
The code examples in the documentation aren't always accurate.
In this one the Range object has been omitted. It should be: Code:
Dim doc As Document, rngRange As Range Set doc = ActiveDocument Set rngRange = _ doc.Range(doc.Paragraphs(1).Range.Start, _ doc.Paragraphs(1).Range.End - 1) rngRange.InsertAfter _ " This is now the last sentence in paragraph one." |
#3
|
|||
|
|||
![]()
Well, never mind! Many thanks, Italophile!
|
#4
|
|||
|
|||
![]()
You are right. The documentation is often wrong. The documentation on CustomXMLParts is deplorable. The documentation is not only often wrong. It is often more complex than in needs to be. In this case, I would have simply used:
Code:
Sub ScratchMacro() 'A basic Word Macro coded by Gregory K. Maxey Dim oRng As Range Set oRng = ActiveDocument.Range oRng.End = ActiveDocument.Range.Paragraphs(1).Range.End - 1 oRng.InsertAfter " This is now the last sentence in paragraph 1" lbl_Exit: Exit Sub End Sub |
#5
|
|||
|
|||
![]()
Many thanks, Gmaxey, for the simplification and comments!
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
zanodor | Word VBA | 5 | 07-15-2022 01:25 AM |
![]() |
trevorc | Excel Programming | 2 | 04-30-2021 05:05 AM |
Change the Column reference 'S' to a range ??? Sheets("Customer").Range("S" & ActiveCell.Row) = Date | trevorc | Excel Programming | 1 | 03-04-2021 02:39 PM |
![]() |
marceepoo | Word VBA | 1 | 03-05-2020 09:41 PM |
![]() |
petec | Word | 10 | 09-25-2011 08:41 AM |