Hallo!
Ich habe folgende Funktion, welche Zahlen in einem Word Dok. markiert. Das funktioniert auch sehr gut - bis zu dem Punkt, an dem man Tabellen im Word Dokument hat. Dann verschieben sich die Markierungen. Woran liegt das?
Function higlightAllNumbers(worddoc As Word.document, Optional reset As Boolean)
Dim myRegExp As RegExp
Dim myMatches As MatchCollection
Dim myMatch As Match
Dim tempMatches As MatchCollection
Dim tempMatch As Match
Set myRegExp = New RegExp
'Alle Funde im String zurückgeben
myRegExp.Global = True
'Suchpattern definieren
myRegExp.pattern = "([\d]+[,.]?)*[\d]+"
Set myMatches = myRegExp.Execute(worddoc.range.Text)
'Schauen wir uns zunächst jede Zahl an...
For Each myMatch In myMatches
'MsgBox myMatch.value & " von " & myMatch.FirstIndex & " länge: " & myMatch.Length
myRegExp.pattern = "[1]+.(([\d]{1,2}|[\d]{4,})[.,]?)+"
Set tempMatches = myRegExp.Execute(myMatch.value)
'Ist diese Zahl ein Datum wie 12.2.2008?
If tempMatches.Count > 0 Then
Set tempMatch = tempMatches.Item(0)
If tempMatch.value = myMatch.value Then
GoTo continue
End If
End If
myRegExp.pattern = "[0-9]{4}[,.]?"
Set tempMatches = myRegExp.Execute(myMatch.value)
'ist der Fund eine Jahreszahl?
If tempMatches.Count > 0 Then
Set tempMatch = tempMatches.Item(0)
If tempMatch.value = myMatch.value Then
GoTo continue
End If
End If
'Alles nein? Toll, dann markiere!
Dim range As Word.range
Set range = worddoc.range(Start:=myMatch.FirstIndex, End:=myMatch.FirstIndex + myMatch.Length)
range.bold = true
continue:
Next
End funtkion
Danke!!!
Gruß,
Richard
\d ↩︎