Search code examples
textms-wordunderline

formatiing part text in a table cell in word


`tab1.Rows(20).Cells.Merge tab1.Rows(20).Cells(1).Range.Text = "2. Brief of Case. " + objVar(6) tab1.Rows(20).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify

tab1.Rows(22).Cells.Merge tab1.Rows(22).Cells(1).Range.Text = "2. Present Status of the Case. " + objVar(8) tab1.Rows(22).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify`

I want the text in the row 20 cell 1 "Brief of Case" only to be bold and underlined ...rest of the text to be normal and similarly the text in row 22 cell 1 "Present Status of the Case" to be undelrlined and bold

`tab1.Rows(20).Cells.Merge tab1.Rows(20).Cells(1).Range.Text = "2. Brief of Case. " + objVar(6) tab1.Rows(20).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify

tab1.Rows(22).Cells.Merge tab1.Rows(22).Cells(1).Range.Text = "2. Present Status of the Case. " + objVar(8) tab1.Rows(22).Cells(1).Range.ParagraphFormat.Alignment = wdAlignParagraphJustify`


Solution

  • For example:

    Dim Rng As Range
    With tab1
      With .Rows(20)
        .Cells.Merge
        Set Rng = .Cells(1).Range
        With Rng
          .ParagraphFormat.Alignment = wdAlignParagraphJustify
          .Text = objVar(6)
          .Collapse wdCollapseStart
          .Text = "2. Brief of Case. "
          .Font.Bold = True
          .Font.Underlined = True
        End With
      End With
      With .Rows(22)
        .Cells.Merge
        Set Rng = .Cells(1).Range
        With Rng
          .ParagraphFormat.Alignment = wdAlignParagraphJustify
          .Text = objVar(8)
          .Collapse wdCollapseStart
          .Text = "2. Present Status of the Case. "
          .Font.Bold = True
          .Font.Underlined = True
        End With
      End With
    End With