We have text that has the following structure. This uses styles and also cross-referencing (to paragraph numbers).
- numbered style
- non-numbered style(s)
- numbered style, but includes cross-reference to numbered style (paragraph format)
- non-numbered style(s)...
Something like this example:
1. Numbered style
some non-numbered style(s)
2. Numbered style that cross-references paragraph #1
some non-number styles(s)
3. Numbered style that cross-references paragraph(s) #1 and/or #2
....
In order to get the cross-references, someone has inserted a cross-reference with a reference type of "numbered item" and an "insert reference to" "paragraph number".
I want to:
a) have someone copy the example text above (from the "active" document)
b) have that person put an insertion point after the example text
c) open a new document and insert the example text, complete with formatting and cross-referencing intact
d) manipulate text in the text of the new document
e) copy the manipulated text and paste back into the "active" document, hopefully retaining the styles and the cross-referencing
This is the code to do (a), (b), and (c):
Code:
Sub Test()
' Prerequisites: copy the formatted text
' Put the insertion point at a paragraph after the copied text, on a blank line
' Declarations
Dim selectedText As Range
Set selectedText = Selection.Range
Dim newDoc As Document
' Add a new document to store the copied text
Set newDoc = Documents.Add
' This adds with all the formatting, including cross-referencing
newDoc.Content.Paste
The document that is created has the styles from the active document and all the cross-referencing too.
How do I manipulate the text in newDoc? (All the code I have uses Selection.Find, which does not seem appropriate.) (E.g., this is a simple find and replace: FindTextA and ReplaceWithTextB.)
Once I manipulate the text, how do I copy the contents of the (revised) newDoc?
Is it possible to copy (and paste) the text complete with the styles and embedded cross-referencing?
Note: the styles in newDoc are the same as what is in the active document. So, assuming the example above is used with three numbered styles, the pasted-in text from newDoc would have 4,5,6 based on the same numbered style.