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