Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get a range of tables and text

Status
Not open for further replies.

Patriotix

Programmer
Sep 28, 2009
1
KZ
I want to copy some range of tables and formatted text from one location to another. I'm using Office 2003/Word/VBA.
I try to use this code:

Set Text_To_Copy = Selection.Range
...
Selection.Range = Text_To_Copy

But I get not formatted text without tables.
And else, I can't use selection.copy and selection.paste metods, I can't use a Clipboard.
My document look like this:

table
text
table
table
text
...

P.S. English isn't my mother tongue :)
 
1. you could use .PasteAndFormat, instead of .Paste

2. is your formatting done manually (rather than using Styles)? If so, consider using Styles, which is how Word is designed to be used.

3. is Text_To_Copy declared as a Range variable?

4. what - exactly - is your code, and what - exactly - is your purpose? Is it a requirement that the area to be copied must be selected? Could you do it as a bookmark? Where are you copying to? Another document? If so, does this document exists, or are you making a new one? Are you copying to another location in the same document? if so, if THAT location is a bookmark, then:
Code:
Selection.Copy
ActiveDocument.Bookmarks("CopyHere") _
   .Range.PasteAndFormat (wdFormatOriginalFormatting)
will copy the selected area, and paste it at the bookmark location (formatted as the original format).

5. Do you have IntelliSense turned on? If you do, then using Ctrl-Spacebar is very handy. It displays the current possible parameters (if any) for properties/methods. In other words:

.PasteAndFormat ( - press Ctrl-Spacebar after the (

will display all the possible choices for .PasteAndFormat, one of which is wdFormatOriginalFormatting.

"A little piece of heaven
without that awkward dying part."

advertisment for Reese's Peanut Butter Cups (a chocolate/peanut butter confection)

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top