Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-10-2023, 06:09 AM
ctviggen ctviggen is offline Working with an active document and new document to retain styles and cross-referencing Windows 10 Working with an active document and new document to retain styles and cross-referencing Office 2016
Advanced Beginner
Working with an active document and new document to retain styles and cross-referencing
 
Join Date: Feb 2021
Posts: 54
ctviggen is on a distinguished road
Default Working with an active document and new document to retain styles and cross-referencing

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.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Code on a button to attach a document to my Word Auto fill document is not working on a Mac reynoldsrjr Word 0 03-30-2020 04:00 AM
Single step Word Styles from Source Document through entire Destination document? xbliss Word 6 08-27-2016 09:36 PM
How to save active document to SharePoint document library Rose roon Word VBA 9 09-22-2015 10:53 PM
document styles and some formatting doesn't appear where should when different people view document Dilbert fan Word 1 08-23-2015 05:07 AM
Working with an active document and new document to retain styles and cross-referencing Cross Referencing w/Track Changes Active Liza Word 1 11-06-2014 12:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:54 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft