Collapsing Ranges and Inserting Tables..... just can't figure it out.

N

neil

Hi,

I'm trying to insert a couple of tables into Word, and have spent a
couple of days trying to figure this out. Either the tables merge
together, or they are displayed in the wrong order.

I thought that using Range.Collapse wdCollapseEnd would take to the
end of the specified range.
However, whatever I am doing, it is inserting text at the start of the
range.

Any ideas where I am going wrong.

Many Thanks
Rgds
Neil.

Code Below (I stripped out the code that populates the table cells,
because there would be just too much code to look at):
----------------------------------------------------------------------

Set tRange = objDoc.Bookmarks("client_table").Range

tRange.Collapse wdCollapseEnd

With tRange
.Text = clientFirstName(currentClient)
.Font.Bold = True
End With

With tRange
.Collapse wdCollapseEnd
.Text = vbCr & vbCr
.Collapse wdCollapseEnd
End With


Set ClientTable = objDoc.Tables.Add(Range:=tRange, _
NumRows:=5, NumColumns:=2)


//////////////////////////////////////////
/// Insert Table Cells - works OK
//////////////////////////////////////////


ClientTable.AutoFormat Format:=wdTableFormatContemporary



If partnerFirstName(currentClient) <> "" Then


Set tRange = objDoc.Bookmarks("client_table").Range


With tRange
.Text = partnerFirstName(currentClient)
.Font.Bold = True
End With

With tRange
.Collapse wdCollapseEnd
.Text = vbCr & vbCr
.Collapse wdCollapseEnd
End With


Set PartnerTable = objDoc.Tables.Add(Range:=tRange, _
NumRows:=4, NumColumns:=2)


//////////////////////////////////////////
/// Insert Table Cells - works OK
//////////////////////////////////////////

PartnerTable.AutoFormat Format:=wdTableFormatContemporary

With tRange
.Collapse wdCollapseEnd
.Text = vbCr & vbCr
.Collapse wdCollapseEnd
End With


End If
 
D

Doug Robbins - Word MVP

Where are the two bookmarks located with respect to one another? what
separates them?

--
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
 
N

neil

It is the same bookmark.

I guess I could use a different bookmark for each piece of text, but
with so many pieces of text and tables I need to add, I would end up
with a template littered with bookmarks.

I declared "Set tRange = objDoc.Bookmarks("client_table").Range" twice
because the tables were collapsing into each other otherwise.

Not sure why. I'm just finding collapsing these ranges a bit tricky.

Many Thanks
Neil.
 
D

Doug Robbins - Word MVP

If it is the same bookmark, it does not surprise me that you were not
getting the desired result using the code that you had.

--
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

It is the same bookmark.

I guess I could use a different bookmark for each piece of text, but
with so many pieces of text and tables I need to add, I would end up
with a template littered with bookmarks.

I declared "Set tRange = objDoc.Bookmarks("client_table").Range" twice
because the tables were collapsing into each other otherwise.

Not sure why. I'm just finding collapsing these ranges a bit tricky.

Many Thanks
Neil.
 

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