Hallo Leute,
ich habe das Problem, dass ich eine Liste von Wörtern automatisch in einem Word Dokument suchen lassen möchte und eine Formatierung zuweisen möchte. Aus einem anderen Forum habe ich bereits einen guten Tipp bekommen, jedoch kann ich damit nur einzelne Wörter und nicht Wortkombinationen suchen und formatieren.
Es sollen die Wortkombination "schöner Hund", aber beispielsweise nicht "dummer Hund" markiert werden. Ist das möglich? Der nette Helfer aus dem anderen Board ist mit meinem Anliegen leider verzeifelt.
Hier der Quelltext:
Sub Format()
Dim vList1 As Variant, vList2 As Variant
Dim intI As Integer
Dim myRange As Range
Dim aWord As Range
vList1 = Array("hund", "katze", "maus") 'blau - fett
vList2 = Array("auto", "haus", "boot") 'rot - fett
Set myRange = ActiveDocument.Range(Start:=0, End:=Selection.End)
For Each aWord In myRange.Words
For intI = 0 To UBound(vList1)
If LCase(vList1(intI)) = Trim$(LCase(aWord)) Then
aWord.Bold = True
aWord.Font.Color = wdColorBlue
Exit For
End If
Next
For intI = 0 To UBound(vList2)
If LCase(vList2(intI)) = Trim$(LCase(aWord)) Then
aWord.Bold = True
aWord.Font.Color = wdColorRed
Exit For
End If
Next
Next
Set myRange = Nothing
End Sub
Vielen Dank!
Liebe Grüße
Nimmermehr |