table in table cell

O

Osiris

I have a table of 1 row and 2 columns
in each of the two cells, I want to put a 7x7 table.
How would I do that ?

Here is what I thought (but it doesnot work: the class structure is
baffling):


With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
Set FooterTable = .Range.Tables.Add(Range:=.Range, NumRows:=1,
NumColumns:=2, _
DefaultTableBehavior:=wdWord9TableBehavior,
AutoFitBehavior:=wdAutoFitWindow)

For i = 1 To 2
With FooterTable
Set MonthTable = .Tables.Add(Range:=.Range.Cell(1, i),
NumRows:=7, NumColumns:=7)

MonthTable.Rows.First.Cells.Merge

MonthTable.Cell(1, 1).Range.Text = "october"
For j =10 To76
MonthTable.Cell(2, j).Range.Text = "day"
Next
End With
Next
' alignment instellen


End With
 
J

Jay Freedman

There were two or three problems in your code:

1. The syntax "Set MonthTable = .Tables.Add(Range:=.Range.Cell(1, i),"
is backwards. What you should have had was "Range:=.Cell(1, i).Range"
to get the range of the desired cell.

2. Even after you get the range of the cell, the cell marker is
included in that range. If you then insert a nested cell in that
range, for some reason Word will only insert one row instead of the
requested seven. The cure is to move the end of the range backward by
one character to exclude the cell marker.

3. Once you've successfully inserted the nested table, the line "For j
= 10 To 76" won't execute because the nested table doesn't have 10
rows, let alone 76 rows. I suspect that was something you were
experimenting with.

This code has been tested:

Dim FooterTable As Table, MonthTable As Table
Dim i As Integer, j As Integer
Dim oRg As Range

With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
Set FooterTable = .Range.Tables.Add(Range:=.Range, _
NumRows:=1, NumColumns:=2, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitWindow)
End With

For i = 1 To 2
Set oRg = FooterTable.Cell(1, i).Range
oRg.MoveEnd wdCharacter, -1 ' exclude cell marker

Set MonthTable = FooterTable.Tables.Add(Range:=oRg, _
NumRows:=7, NumColumns:=7)

MonthTable.Rows.First.Cells.Merge

MonthTable.Cell(1, 1).Range.Text = "october"
For j = 1 To 7
MonthTable.Cell(2, j).Range.Text = "day"
Next
Next

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top