Option Explicit
Option Compare Text
Sub TestReplace()
Call ReplaceInFormfieldResult("VBA", "VBAX")
End Sub
Private Sub ReplaceInFormfieldResult(sFind As String, sReplace As String)
Dim oFld As Word.FormField
With Application.ActiveDocument
If .ProtectionType <> wdNoProtection Then .Unprotect
For Each oFld In .FormFields()
If oFld.Type = wdFieldFormTextInput And oFld.TextInput.Type = wdRegularText Then
oFld.Result = _
Replace(oFld.Result, sFind, sReplace, 1, -1, vbTextCompare)
End If
Next
.Protect wdAllowOnlyFormFields, True
End With
End Sub
|