#1
|
|||
|
|||
Copying and pasting pages with changes
I have a document which has Track Changes turned on. I want to select any pages that have a revision made to it and copy it to a 2nd document. I would also like to, if possible, include the footer contents of the page I'm copying. The first part is giving me problems, however. Here is the code I'm using:
Code:
For Each oRevision In oDoc.Revisions revNum = revNum + 1 'If this page hasn't already been copied (for multiple revisions on single page) If oRevision.Range.Information(wdActiveEndPageNumber) <> nLastPageNum Then 'Also check that the change is not in the header or footer If oRevision.Range.StoryType = wdMainTextStory Then MsgBox (oRevision.Range.Text) 'Add 1 to counter n = n + 1 oDoc.Activate ActiveDocument.Bookmarks("\Page").Select Selection.Copy oNewDoc.Activate Selection.EndKey wdStory Selection.InsertBreak (wdPageBreak) Selection.PasteAndFormat wdPasteDefault nLastPageNum = oRevision.Range.Information(wdActiveEndPageNumber) End If End If Next oRevision Chris |
#2
|
||||
|
||||
Try something along the lines of:
Code:
Sub Demo() Dim DocSrc As Document, DocTgt As Document, i As Long, Rng As Range Set DocSrc = ActiveDocument: Set DocTgt = Documents.Add With DocSrc For i = 1 To .ComputeStatistics(wdStatisticPages) Set Rng = .Range.GoTo(What:=wdGoToPage, Name:=i) Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page") If Rng.Revisions.Count > 0 Then With DocTgt.Range .InsertAfter Chr(12) .Characters.Last.FormattedText = Rng.FormattedText End With End If Next End With End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
Cross-posted at: http://www.vbaexpress.com/forum/show...ent-to-new-one
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#4
|
|||
|
|||
Thank you! It works like a charm now with one issue that I already found out about that when I paste into the new document, the section numbers change. I need to figure out if there's a way to keep the section numbers from the original document.
|
#5
|
||||
|
||||
That is one of the limitations you encounter when copying parts of one document to another. An alternative approach that might work better for you is to make a copy of the document then delete pages that have no changes (keeping Section breaks intact). That will also mean you automatically get the original header/footer content with no additional code.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Copying, Cutting and pasting | Steve0513 | Excel | 1 | 07-13-2017 05:09 PM |
copying and pasting text format | paik1002 | Excel | 2 | 10-07-2016 02:34 AM |
Prevent Copying and Pasting | Jimmy Tsawo | Excel | 3 | 02-20-2014 03:54 AM |
Copying and pasting from Excel | Lorna B | Word | 1 | 03-20-2012 11:58 PM |
Copying & Pasting to Firefox problems | mso2u | Word | 2 | 04-07-2011 07:26 AM |