Table formatting

K

KC8DCN

I have a document that has about 60 tables in it.

I'm working on a macro that will insert a row the second row, copy the
formatting in row 2 column 1 and apply that to the rest of the cells in that
column, copy the formatting in row 2 cell 2 and apply that to the rest of the
cells in that column, etc., and then delete the extra row that was inserted
to copy the formatting from.

The formatting in the extra row contains a specific font size, style and a
decimal tab.

I have, however, been unsuccessful in finding how to copy the formatting of
one cell and apply it to another. Is this possible?

Thanks!
 
J

Jezebel

The trick is that cells don't have formatting: that belongs to the range
within the cell, eg

Dim pTable as Word.Table
Dim pR1 As Word.Range
Dim pR2 As Word.Range
Dim pColumn as long
Dim pRow As Long

Set pTable = Selection.Tables(1)

For pColumn = 1 to pTable.Columns.Count
Set pR1 = pTable.Cell(2, pColumn).Range

for pRow = 3 to pTable.Rows.Count
Set pR2 = pTable.Cell(pRow, pColumn).Range

With pR1.Font
pR2.Font.Bold = .Bold
pR2.Font.Color = .Color
pR2.Font.Size = .Size
: [there are lots of properties you might want to set...]
End With
Next
Next

But what's the point of inserting the row? -- The row you insert will
inherit the format from the row above, so why not use that?
 
K

KC8DCN

The first row has the column headings in it; the second, has the formatting
that I would like for the rest of the column. By inserting a row above the
second row, I can insert the information that I want, grab the formatting in
the second row and copy that to the rest of the column.

I'll try that. Thanks!

Jezebel said:
The trick is that cells don't have formatting: that belongs to the range
within the cell, eg

Dim pTable as Word.Table
Dim pR1 As Word.Range
Dim pR2 As Word.Range
Dim pColumn as long
Dim pRow As Long

Set pTable = Selection.Tables(1)

For pColumn = 1 to pTable.Columns.Count
Set pR1 = pTable.Cell(2, pColumn).Range

for pRow = 3 to pTable.Rows.Count
Set pR2 = pTable.Cell(pRow, pColumn).Range

With pR1.Font
pR2.Font.Bold = .Bold
pR2.Font.Color = .Color
pR2.Font.Size = .Size
: [there are lots of properties you might want to set...]
End With
Next
Next

But what's the point of inserting the row? -- The row you insert will
inherit the format from the row above, so why not use that?



KC8DCN said:
I have a document that has about 60 tables in it.

I'm working on a macro that will insert a row the second row, copy the
formatting in row 2 column 1 and apply that to the rest of the cells in
that
column, copy the formatting in row 2 cell 2 and apply that to the rest of
the
cells in that column, etc., and then delete the extra row that was
inserted
to copy the formatting from.

The formatting in the extra row contains a specific font size, style and a
decimal tab.

I have, however, been unsuccessful in finding how to copy the formatting
of
one cell and apply it to another. Is this possible?

Thanks!
 

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