PDA

View Full Version : [SOLVED:] Change Font in a table Cell



watkins77
09-12-2013, 09:46 PM
I am trying to change the font size and color of text within a single cell of a table as below.



Cell 1-1 - Line one
Cell 1-1 - Line two






I can't seem to define the range to only be used for a specific text, therefore anything in that cell gets the same font style! :banghead:

My example code is below - any help would be much appreciated.

Set objRange = objSelection.Range
objDoc.Tables.Add objRange, 1, 1
Set objTable = objDoc.Tables(1)

With objTable.Cell(1, 1)
    .Shading.BackgroundPatternColor = RGB(245,245,245)
    Set rng = .Range
    rng.Font.Color = RGB(255,0,0)
    rng.Font.Name = "Arial"
    rng.Font.Size = "12"
    rng.Font.Bold = True    
    rng.InsertAfter "Cell 1-1 - Line one"
    rng.InsertAfter Chr(11)
    rng.Font.Color = RGB(0,0,255)
    rng.Font.Name = "Arial"
    rng.Font.Size = "16"
    rng.Font.Bold = False    
    rng.InsertAfter "Cell 1-1 - Line two"    
End With 

watkins77
09-13-2013, 12:28 AM
This seems to work ... is there a more correct way of coding it?

With objTable.Cell(1, 1)
    .Shading.BackgroundPatternColor = RGB(245,245,245)
    With .Range.Select
        Set objSelection = objWord.Selection
        objSelection.Font.Name = "Arial"
        objSelection.Font.Color = RGB(255,0,0)
        objSelection.Font.Size = 12
        objSelection.Font.Bold = True
        objSelection.TypeText "Cell 1-1 - Line one" & Chr(11)
        Set objSelection = objWord.Selection
        objSelection.Font.Name = "Arial"
        objSelection.Font.Color = RGB(0,0,255)
        objSelection.Font.Size = 16
        objSelection.Font.Bold = False
        objSelection.TypeText "Cell 1-1 - Line two"
    End With 
End With