Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Inserting range into new document without losing formating

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry - 07 Feb 2005 22:25 GMT
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 - 07 Feb 2005 22:59 GMT
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

> I have a simple macro that pastes the selected text into a new document.
>
[quoted text clipped - 13 lines]
> Is there any way to use the Range to insert the text, without losing
> formatting?
Doug Robbins - 08 Feb 2005 00:23 GMT
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

Signature

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

>I have a simple macro that pastes the selected text into a new document.
>
[quoted text clipped - 13 lines]
> Is there any way to use the Range to insert the text, without losing
> formatting?
Larry - 08 Feb 2005 00:58 GMT
Great, Doug.  Thanks much.

Larry

> From the Visual Basic Help File
>
[quoted text clipped - 28 lines]
> > Is there any way to use the Range to insert the text, without losing
> > formatting?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.