Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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 |
#3
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Text form field inside a WORD table cell, odd behavior when select | Tables | |||
Text form field inside WORD table cell, odd selection behavior | Microsoft Word Help | |||
Creating a Table of Figures | Microsoft Word Help | |||
Table headers/footers and layout | Page Layout | |||
Table AutoFormats vs. Table Styles confusion | Tables |