MrudulaYamini

Hi Guys,

Im facing a problem when Im trying to create multiple tables using office tools(Word) in .net. The first page is getting displayed pretty fine, but in the next page the table is getting displayed in an other table there by distorting rest of the pages. I will be thankful if any one can help me out of this. If the problem is with going for next line after the table , why is first page not getting effected by it

Send me the code if any to
My mail Id-mrudula_yamini@yahoo.com



Re: Visual Studio Tools for Office How to avoid the problem of table getting created with in another table

Cindy Meister

This is difficult to answer without seeing how your code is creating tables, currently.

To answer generally, if you create a table, assigning it to an object variable, you need to get that table's range, assign it to a variable, then collapse the range. Insert a paragraph mark to separate the two tables, then create the next table. The VBA code would look something like this:

Sub CreateNewTable()

Dim tbl as Word.Table
Dim rng as Word.Range

'User selection as starting point
Set rng = Selection.Range
'Create a new table at this point
Set tbl = rng.Tables.Add('Parameters here)
'Get the table's range
Set rng = tbl.Range
'Insert a paragraph after the table
rng.InsertAfter Chr$(13) 'vbCR = carriage return
'Collapse the range to its end-point
rng.Collapse wdCollapseEnd
'Insert the next table
Set tbl = rng.Tables.Add('Parameters here)

End Sub