Selecting more than one table cell in a Word document

J

James Lavery

I'm using Microsoft.Office.Interop.Word from a VB.NET application to
create a Word 2003 document with tables in it.

I need to merge cells 2 and 3 in a row, while leaving cell 1 intact.
The problem is that I cannot see how I can programmatically select
just cells 2 and 3. Using the Cell.Select method just selects the
current cell.

Can someone point me in the right direction, please?

Thanks,

James
 
C

Cindy M.

Hi James,
I'm using Microsoft.Office.Interop.Word from a VB.NET application to
create a Word 2003 document with tables in it.

I need to merge cells 2 and 3 in a row, while leaving cell 1 intact.
The problem is that I cannot see how I can programmatically select
just cells 2 and 3. Using the Cell.Select method just selects the
current cell.
You shouldn't need to select the cells at all in order to merge them.
Here's a code snippet that gets the range for the cell in row 2,
column 2 and the cell in row 2, column 4. Then a range is set to
include both of them (the end point of the first one is extended to
the end point of the second), all the cells of that range are
referenced, and the cells merged

Dim rngCell1 As Word.Range, rngCell2 As Word.Range

Set rngCell1 = ActiveDocument.Tables(1).Cell(2, 2).Range
Set rngCell2 = ActiveDocument.Tables(1).Cell(2, 4).Range
rngCell1.End = rngCell2.End
rngCell1.Cells.Merge


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top