Discussion:
Inserting range into new document without losing formating
(too old to reply)
Larry
2005-02-07 22:25:46 UTC
Permalink
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?
arne
2005-02-07 22:59:15 UTC
Permalink
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
Post by 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
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?
Doug Robbins
2005-02-08 00:23:58 UTC
Permalink
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
Post by 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
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?
Larry
2005-02-08 00:58:07 UTC
Permalink
Great, Doug. Thanks much.

Larry
Post by 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
Post by 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
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?
Loading...