L
Lucy in the sky
Working with Word 2003.
I have a table formatting function to apply font format from a table cell to
another table.
While code fragment #1 works fine, I would expect code fragment #2 behaves
the same. However, it is not. I have to modify it to code fragment #3 to make
it work as I expected.
Private Sub FormatTable()
Dim objSourceTable As Word.Table
Dim objTargetTable As Word.Table
Dim objSourceFont As Word.Font
Set objSourceTable = <get a reference to table A in active document>
Set objTargetTable = <get a reference to table B in active document>
Set objSourceFont = objSourceTable.Cell(1, 1).Range.Font.Duplicate
' #1 - OK, font attributes applied correctly
objTargetTable.Cell(2, 2).Font = objSourceFont
' #2 - Not OK
objTargetTable.Columns(1).Select
objTargetTable.Application.Selection.Font = objSourceFont
' #3 - OK
objTargetTable.Columns(1).Select
objTargetTable.Application.Selection.Font.Bold = objSourceFont.Bold
<apply other attribute one by one>
...........
End Sub
Therefore I would like to verify why #2 is not working? What is the proper
way to apply font attributes? Looks like #1 is faster?
I have a table formatting function to apply font format from a table cell to
another table.
While code fragment #1 works fine, I would expect code fragment #2 behaves
the same. However, it is not. I have to modify it to code fragment #3 to make
it work as I expected.
Private Sub FormatTable()
Dim objSourceTable As Word.Table
Dim objTargetTable As Word.Table
Dim objSourceFont As Word.Font
Set objSourceTable = <get a reference to table A in active document>
Set objTargetTable = <get a reference to table B in active document>
Set objSourceFont = objSourceTable.Cell(1, 1).Range.Font.Duplicate
' #1 - OK, font attributes applied correctly
objTargetTable.Cell(2, 2).Font = objSourceFont
' #2 - Not OK
objTargetTable.Columns(1).Select
objTargetTable.Application.Selection.Font = objSourceFont
' #3 - OK
objTargetTable.Columns(1).Select
objTargetTable.Application.Selection.Font.Bold = objSourceFont.Bold
<apply other attribute one by one>
...........
End Sub
Therefore I would like to verify why #2 is not working? What is the proper
way to apply font attributes? Looks like #1 is faster?