Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Eric Schmieder
 
Posts: n/a
Default Creating a table inside an existing table

I am having great difficulty with wht seems to be a simple task. I am trying
to nest one table in Word inside the cell of an existing table and each time
I create the second table and populate it only the last row displays in the
resulting word document. I am using VB.NET 2003 and Word 2003. Any help is
greatly appreciated. My VB code is below.

-------------------Begin Code-------------------
Dim wdApp As Word.Application
wdApp = CType(CreateObject("Word.Application"), Word.Application)
wdApp.Documents.Add()
wdApp.ActiveDocument.Tables.Add(wdApp.ActiveDocume nt.Range, 5, 4)
wdApp.ActiveDocument.Tables.Item(1).Cell(1, 1).Range.Select()
wdApp.Selection.Text = "A"
wdApp.ActiveDocument.Tables.Item(1).Cell(1, 2).Range.Select()
wdApp.Selection.Text = "B"
wdApp.ActiveDocument.Tables.Item(1).Cell(1, 3).Range.Select()
wdApp.Selection.Text = "C"
wdApp.ActiveDocument.Tables.Item(1).Cell(1, 4).Range.Select()
wdApp.Selection.Text = "D"
wdApp.ActiveDocument.Tables.Item(1).Cell(2,
1).Merge(wdApp.ActiveDocument.Tables.Item(1).Cell( 2, 4))
wdApp.ActiveDocument.Tables.Item(1).Cell(2, 1).Range.Select()
Dim selectedtable As Word.Table
selectedtable = wdApp.Selection.Tables.Add(wdApp.Selection.Range, 3,
3)
selectedtable.Cell(1, 1).Range.Text = 1
selectedtable.Cell(1, 2).Range.Text = 2
selectedtable.Cell(1, 3).Range.Text = 3
selectedtable.Cell(2, 1).Range.Text = 4
selectedtable.Cell(2, 2).Range.Text = 5
selectedtable.Cell(2, 3).Range.Text = 6
selectedtable.Cell(3, 1).Range.Text = 7
selectedtable.Cell(3, 2).Range.Text = 8
selectedtable.Cell(3, 3).Range.Text = 9
wdApp.ActiveDocument.Tables.Item(1).Cell(3, 1).Range.Select()
wdApp.Selection.Text = "A"
wdApp.ActiveDocument.Tables.Item(1).Cell(3, 2).Range.Select()
wdApp.Selection.Text = "B"
wdApp.ActiveDocument.Tables.Item(1).Cell(3, 3).Range.Select()
wdApp.Selection.Text = "C"
wdApp.ActiveDocument.Tables.Item(1).Cell(3, 4).Range.Select()
wdApp.Selection.Text = "D"
wdApp.ActiveDocument.Tables.Item(1).Cell(4, 1).Range.Select()
wdApp.Selection.Text = "A"
wdApp.ActiveDocument.Tables.Item(1).Cell(4, 2).Range.Select()
wdApp.Selection.Text = "B"
wdApp.ActiveDocument.Tables.Item(1).Cell(4, 3).Range.Select()
wdApp.Selection.Text = "C"
wdApp.ActiveDocument.Tables.Item(1).Cell(4, 4).Range.Select()
wdApp.Selection.Text = "D"
wdApp.ActiveDocument.Tables.Item(1).Cell(5, 1).Range.Select()
wdApp.Selection.Text = "A"
wdApp.ActiveDocument.Tables.Item(1).Cell(5, 2).Range.Select()
wdApp.Selection.Text = "B"
wdApp.ActiveDocument.Tables.Item(1).Cell(5, 3).Range.Select()
wdApp.Selection.Text = "C"
wdApp.ActiveDocument.Tables.Item(1).Cell(5, 4).Range.Select()
wdApp.Selection.Text = "D"
wdApp.Visible = True
-----------End Code-----------------------

The result being produced is the following:

A B C D
7 8 9

A B C D
A B C D
A B C D

 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Text form field inside a WORD table cell, odd behavior when select pwrichcreek Tables 9 October 20th 05 12:34 AM
Text form field inside WORD table cell, odd selection behavior pwrichcreek Microsoft Word Help 1 October 11th 05 03:57 PM
Creating a Table of Figures Dee Microsoft Word Help 7 July 14th 05 12:15 AM
Table headers/footers and layout Keith Page Layout 1 April 8th 05 07:37 PM
Table AutoFormats vs. Table Styles confusion Tony Jollans Tables 5 March 6th 05 07:18 PM


All times are GMT +1. The time now is 08:44 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"