Reply
 
Thread Tools Display Modes
  #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

  #2   Report Post  
Charles Kenyon
 
Posts: n/a
Default

I would suggest posting this in the word.vba.general or word.vba.beginners
newsgroup.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"Eric Schmieder" Eric wrote in message
...
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



  #3   Report Post  
Eric Schmieder
 
Posts: n/a
Default

Thank you for the suggestion. In the interim I found a work around although
the solution made little to no sense. By simply adding text into the cell
before trying to create the table, all rows of the nested table appear
correctly and the text entered into the selection never does. When leaving
the cell blank as in the original post prior to building the nested table
within the cell, only the last row of the nested table appears. Weird, but
works with the minor change. If anyone has insight as to why this is the
case, I'd love to know. In the meantime I will just assume it is a bug in the
Word Object and move on with the funcitonal work around. Thanks for taking
the time to respond.

Eric Schmieder

"Charles Kenyon" wrote:

I would suggest posting this in the word.vba.general or word.vba.beginners
newsgroup.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

"Eric Schmieder" Eric wrote in message
...
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




Reply
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 07:51 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"