# VBA in Word - Text Format Overwriting with InsertAfter when adding text within a Table Cell



## inosent (Oct 17, 2016)

I am using this code to insert an underlined and bold header with a non-formatted paragraph underneath. I am able to append the second paragraph below the header in the cell, but I lose the formatting for the header:


```
Sub T1()
Dim myText1 As String
Dim myText2 As String
myText1 = "Header"
myText2 = "A medium sized paragraph with 3-5 sentences. A medium sized paragraph with 3-5 sentences. A medium sized paragraph with 3-5 sentences. "
    
With ActiveDocument.Tables(1).Cell(2, 2).Range
.Font.Name = "Times New Roman"
.Font.Size = 12
.Font.Bold = True
.Font.Underline = True
.Text = myText1 & vbCr & vbCr
.Font.Bold = False
.Font.Underline = False
.InsertAfter myText2

    End With

End Sub
```

The result is supposed to look like this:

<b><u>Header</u></b>

A medium sized paragraph with 3-5 sentences. A medium sized paragraph with 3-5 sentences. A medium sized paragraph with 3-5 sentences. 

But I get:

Header

A medium sized paragraph with 3-5 sentences. A medium sized paragraph with 3-5 sentences. A medium sized paragraph with 3-5 sentences.


----------



## Macropod (Oct 18, 2016)

Try:

```
Sub T1()
Dim myText1 As String, myText2 As String
myText1 = "Header"
myText2 = "A medium sized paragraph with 3-5 sentences. A medium sized paragraph with 3-5 sentences. A medium sized paragraph with 3-5 sentences. "
    
With ActiveDocument.Tables(1).Cell(2, 2).Range
  With .Font
    .Name = "Times New Roman"
    .Size = 12
  End With
  .Text = myText1 & vbCr & vbCr & myText2
  With .Paragraphs.First.Range.Font
    .Bold = True
    .Underline = True
  End With
End With
End Sub
```


----------

