Inserting range into new document without losing formating

L

Larry

I have a simple macro that pastes the selected text into a new document.

Selection.copy
Documents.Add
Selection.Paste

I thought of doing the same with a range. This works, but all character
formatting is lost:

Dim Target As Document, r As Range
Set r = Selection.Range
Set Target = Documents.Add
Target.Range.InsertAfter r & vbCr
Target.Activate

Is there any way to use the Range to insert the text, without losing
formatting?
 
A

arne

try

Sub copy_page_nothing_lost()
ActiveDocument.Bookmarks("\page").Range.Copy
Documents.Add
Selection.Paste
End Sub
Sub ccpy_section_nothing_lost()
ActiveDocument.Bookmarks("\Section").Range.Copy

Documents.Add
Selection.Paste
End Sub

arne
 
D

Doug Robbins

From the Visual Basic Help File

This example copies the text and formatting from the selection into a new
document.

Set myRange = Selection.FormattedText
Documents.Add.Content.FormattedText = myRange

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
L

Larry

Great, Doug. Thanks much.

Larry


Doug Robbins said:
From the Visual Basic Help File

This example copies the text and formatting from the selection into a new
document.

Set myRange = Selection.FormattedText
Documents.Add.Content.FormattedText = myRange

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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