Juhuuuu, ((hier)) ist die Lösung:
((hier)) wird durch ein Textformularfeld ersetzt mit dem Vorgabetext „hier“:
Option Explicit
Option Compare Text
Sub LösungDurchTextfelder()
Dim wdFeld As FormField
Dim strLösung As String
On Error GoTo ende
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect
End If
’ heben den Schutz auf falls nötig
Selection.HomeKey wdStory
’ gehe zum Anfang des Dokuments
Do
Selection.Find.ClearFormatting
With Selection.Find
.Text = „((“
.Replacement.Text = „“
.Forward = True
End With
Selection.Find.Execute
Selection.Extend
With Selection.Find
.Text = „))“
.Replacement.Text = „“
.Forward = True
End With
Selection.Find.Execute
’ suche ((xxx)) und markiere
If Selection.Range „“ Then
strLösung = Selection.Range
strLösung = Replace(strLösung, „((“, „“)
strLösung = Replace(strLösung, „))“, „“)
Set wdFeld = Selection.FormFields.Add(Range:=Selection.Range, Type:=wdFieldFormTextInput)
wdFeld.TextInput.Default = strLösung
’ ersetze durch Textfeld
Selection.ExtendMode = False
Else
Exit Do
End If
Loop
ActiveDocument.Protect wdAllowOnlyFormFields, True ’ Schutz
Exit Sub
ende:
MsgBox Err.Description, vbInformation, „Fehler“
End Sub