Merging rows in a single column

D

Derek

ok so I have a vbscript routine that populates a table in a word document, I
can merge cells in a row but for some reason I can't merge 3 rows in a single
column. Below is the code (that works) for mergin cells in a single row, my
question is how do I merge rows in a column?

Set oRng = objDocument.Range (<cTable>.Cell(1,2).Range.start,
<cTable.Cell(1,6).Range.End)
oRng.Cells.Merge.

Thanks in advance,

Derek
 
D

Doug Robbins - Word MVP

The following will merge the cell in which the Selection is located with the
two cells beneath it:

Selection.Cells(1).Range.Select
Selection.MoveDown wdLine, 1, wdExtend
Selection.Cells.Merge
Selection.MoveDown wdLine, 1, wdExtend
Selection.Cells.Merge


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
D

Derek

Hey Doug, ok in my vbscript app if I use the following I can select the 1st
cell in the 1st row, but I cannot figure out how to select the next 2 rows in
the column. Here is the code I used to select the 1st cell in the 1st row

Set tbl = rng.ConvertToTable
tbl.Range.Cells(1).Range.Select

When I try to do the MoveDown afterwards I get an error and it doesn't
select the next cell in the column.

Hopefully this makes sense.

Thanks,

Derek
 
D

Doug Robbins - Word MVP

I do not know what you have included in the Range rng, but if I select the
text that I want to convert to a table and then merge the first three cells
in the first column of that table, the following works fine for me:

Dim rng As Range
Set rng = Selection.Range
Set tbl = rng.ConvertToTable
tbl.Range.Cells(1).Range.Select
Selection.MoveDown wdLine, 1, wdExtend
Selection.Cells.Merge
Selection.MoveDown wdLine, 1, wdExtend
Selection.Cells.Merge


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
D

Derek

Hey doug, the problem I have is that all vars in this vbscript environment
are defaulted to type "Variant" so I can't dim a var as anything but. I can
however use the "Set var = objDocument.Range". So after I have selected the
cell using the method you have described (which works) I can't just use
"Selection.Movedown" as it complains that "Selection" is undefined"

So how would I set a var to the currently selected cell? I guess that's the
million dollar question...

Thanks for your help so far!!!

Derek
 
D

Doug Robbins - Word MVP

Sorry, I do not know anything about VBScript, but is there a facility to set
a reference to the Word Object Model? I would think that if you can do
that, the code should work as in the Word Object Model, there is definitely
a Selection object.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
D

Derek

Hey Doug, ok I figured it out,

Set oCeLL1 = tbl.Cell(1,1)
Set oCell2 = tbl.Cell(2,1)
Set oCell3 - tbl.Cell(3,1)

oCell2.Merge(oCell3)
oCeLL1.Merge(oCell2)

Just thought I would let you know

thanks for all your help!

Derek
 

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