PDA

View Full Version : Content.PasteAndFormat behaves differently if tables exist in the text



ybolotin
11-04-2010, 07:16 AM
WinXP Pro (32-bit)
Office 2007 (Excel, Word, Outlook)

I have a table of values (in a Word .docx), and one of the columns includes formatted text.
There is a script which copies this text, and pastes into an Outlook message (Outlook uses Word as the default editor)

The following code does this:




.Cell(j, 9).Select
Selection.Copy

Set objDoc = oItem.GetInspector.WordEditor
objDoc.Content.PasteAndFormat (wdPasteDefault)




The following behavior is then observed:

For formatted text which does NOT include embedded tables:

the CONTENTS of the cell are pasted (this is what I want, the text looks as it would look if i just typed it in)For formatted text which DOES contain embedded tables (whether created in word, copied from Excel, whatever)

the CELL ITSELF (i.e. cell(j, 9)) is pasted - including borders, height and width, etc. This is made more annoying by the fact that the left edge of the cell is not at the left edge of the resulting email, but about 2 inches offscreen (so the entire left side of the final result is hidden from view)(using the other wd... options in PasteAndFormat results in either nothing getting pasted, or the same behavior being replicated)


I need this text to maintain formatting, and to be able to handle data both with and without tables.

Lacking that, I need a way to automatically adjust the position of the resultant cell-with-embedded-tables which won't break the non-embedded-table text

Any help would be vastly appreciated.

Thanks!

Sebastian H
11-04-2010, 03:33 PM
The following works with Word 2003: Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="outsideoftable"
Selection.PasteAndFormat (wdPasteDefault)


That also works (at least manually) when pasting into an OL message. If the above works for you within Word, then maybe you can copy it in two steps? Select what you've copied in the intermediate place and then copy it to the e-mail.

ybolotin
11-05-2010, 06:14 AM
The following works with Word 2003:

this appears to be a bug with Word 2007, albeit one I haven't found a workaround for

the code is not required, you can see this behavior by doing the following:
1) create a 1x2 Word table
2) insert any text in cells 1 and 2
3) insert another table inside cell 2

then:
4) copy cell 1 (i.e. move the mouse until the cursor turns into a black arrow, click it, then copy)
5) paste into another word document (or the same one, just outside the table) - you get text

then:
6) copy cell 2
7) paste into another word document - you get a cell, with borders and everything

Sebastian H
11-05-2010, 08:57 AM
this appears to be a bug with Word 2007
Maybe they meant it to be a feature, like the other automatic selection expansions they introduced in previous versions. In that case, they should have put an entry in the compatibility options for it, which you could change to the old behavior.


you get a cell, with borders and everything You mean, at least two cells: one table (with at least one cell and everything else you want) in one surrounding cell you don't want, right?

Another whacko idea: If the above doesn't work, maybe you could somehow use FrontPage? That has a nice way of allowing selection of surrounding tags, on any level you wish.

ybolotin
11-17-2010, 08:30 AM
You mean, at least two cells: one table (with at least one cell and everything else you want) in one surrounding cell you don't want, right?


yeah, sorry.
...
5) [the first paste will result in] plain text, no cells anywhere
...
7) [the second paste will result in] a cell, with text and an embedded table inside it




maybe you could somehow use FrontPage?


unfortunately not everyone has frontpage installed, so this limits portability too much.

thanks for your advice, though!

Sebastian H
11-17-2010, 10:25 AM
So, did you try the compatibility options?

ybolotin
11-17-2010, 10:52 AM
So, did you try the compatibility options?

this might sound stupid, but... how exactly do i do this?

Sebastian H
11-17-2010, 11:45 AM
In Word XP it's under Tools → Options → Compatibility. Not sure where it's in your version.