Remove page (from multiple documents) and insert in new document

D

Dylan

So far I have managed to copy the section to the clipboard
with:
[SNIP]
For Each aSection In Target.Sections
If InStr(aSection.Headers
(wdHeaderFooterPrimary).Range, "Section 5") > 0 Then
Set aRange = aSection.Range
aRange.End = aRange.End - 1
aRange.Select
aRange.Paste
Flag = 0
Exit Sub
Else
Flag = 1
End If
Next aSection
If Flag = 1 Then
MsgBox "There was no Section 5", , "Error"
End If
[SNIP]

Now I want to paste this into another document then open
the next report, copy that section 6 to clipboard, paste
into other document (Appending the previous paste), open
next report, and so on.

Any help appreciated.
 
A

Astrid

Hi Dylan,

There's no need to use the clipboard, just use the FormattedRange property:

--------------------------------------------------------
Sub CopySections()
Dim oSection As Section
Dim oRange As Range
Dim oDocCopyFrom As Document
Dim oDocCopyTo As Document

'Define the document where we're
'going to copy from
Set oDocCopyFrom = ActiveDocument
'Define the document were we're
'goint to copy to
'In this example, a new document
'But can be another opened document of course
Set oDocCopyTo = Documents.Add
'Loop through the sections in the first
'document
For Each oSection In oDocCopyFrom.Sections
'Define the range where we're going to copy to
Set oRange = oDocCopyTo.Content
oRange.Collapse direction:=wdCollapseEnd
'Copy to new document
oRange.FormattedText = oSection.Range
Next

'Clean objectvariables
Set oSection = Nothing
Set oRange = Nothing
Set oDocCopyTo = Nothing
Set oDocCopyFrom = Nothing

End Sub
--------------------------------------------------------

Hope this helps,
regards,
Astrid

So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top