Bom dia
Preciso substituir um texto, para um novo texto, porém esse novo texto precisa ficar em negrito, a substituição esta ocorrendo, mas a formação não ocorre.
Segue a abaixo os códigos testes
Sub Teste()
Dim appWord As New Word.Application, appDoc As New Word.Document
appWord.Visible = True
appWord.Documents.Add
Set appDoc = appWord.ActiveDocument
WordDados appWord, "<N>Testando</N> linha 1"
WordDados appWord, "<N>Testando</N> linha 2"
WordDados appWord, "Testando linha 3"
End Sub
Private Sub WordDados(ByRef p_Doc As Word.Application, ByVal p_Texto As String)
Dim TextoNegrito As String
If InStr(UCase(p_Texto), "<N>") <> 0 Then
TextoNegrito = Mid(p_Texto, InStr(UCase(p_Texto), "<N>"))
TextoNegrito = Mid(TextoNegrito, 1, InStr(UCase(p_Texto), "</N>") + 3)
p_Doc.Selection.TypeText p_Texto & vbNewLine
With p_Doc.Selection.Find
.Text = TextoNegrito
.Replacement.ClearFormatting
.Replacement.Font.Bold = True
.Replacement.Text = Replace(Replace(TextoNegrito, "<N>", ""), "</N>", "")
.Format = False
.Wrap = wdFindContinue
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Else
p_Doc.Selection.TypeText p_Texto & vbNewLine
End If
End Sub