pasting into a bookmark that spans more than one table cell

User avatar
stuck
Panoramic Lounger
Posts: 8128
Joined: 25 Jan 2010, 09:09
Location: retirement

pasting into a bookmark that spans more than one table cell

Post by stuck »

Given a 5x5 Word table I can create a bookmark that spans some but not all of the cells in the table, e.g. I can bookmark from column 3 row 2 down and across to column 5 row 5. Meanwhile in Excel I've got a block of cells that are exactly the same size (3 cols wide by 4 rows high).

I would like to do something like:

Code: Select all

Set BMRange = ActiveDocument.Bookmarks("bmkInTable").Range
BMRange.Text = xlWsh.Range("C11:E14").Text
ActiveDocument.Bookmarks.Add "bmkInTable", BMRange
but the above code errors, 'invalid use of null'.

Can my code, which works fine if the bookmark is a single cell, be adapted for a bookmark that spans more than one cell?

Ken

User avatar
HansV
Administrator
Posts: 78238
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: pasting into a bookmark that spans more than one table c

Post by HansV »

You could do it like this:

xlWsh.Range("C11:E14").Copy
BMRange.PasteSpecial DataType:=wdPasteText

This will preserve the bookmark, so you don't need to recreate it.
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8128
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: pasting into a bookmark that spans more than one table c

Post by stuck »

Thank you that worked. Except that the pasted text didn't inherit the formatting in the table whereas when my original code pastes into a bookmark in single cell the pasted text does reflect the formatting of the destination cell.

Ken

User avatar
stuck
Panoramic Lounger
Posts: 8128
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: pasting into a bookmark that spans more than one table c

Post by stuck »

A bit of Googling led me to trying a different data type =wdpasteRTF, that seems to give me what I want.

Ken