View Single Post
  #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