Hello,
So here is the code:
Private Sub replaceMarksInRng(rng As range)
On Error GoTo Handler:
' ranges
Dim ch As range
Dim markRng As range
Dim isLocked As Boolean
' variable utils
Dim key As String
Dim value As String
Dim length As Integer
Set ch = rng
Do
If (StrComp(ch.text, "<") = 0) Then
' prepare the range of the next mark
Set markRng = ActiveDocument.range(ch.Start, ch.End)
Do
Set ch = ch.Next
Loop While StrComp(ch.text, ">") <> 0
' select the mark's range to be able to modify it
Set markRng = ActiveDocument.range(Start:=markRng.Start, End:=ch.End)
markRng.Select
' retrieve key and value
key = ActiveDocument.range(markRng.Start + 1, markRng.End - 1).text
value = dicPatDat(key)
length = Len(value)
Options.ReplaceSelection = True
If dicPatDat.exists(key) And length > 0 Then
value = dicPatDat(key)
modifySelect value
Else
Selection.delete
End If
' go to the next range or calculate the next one if the new text wasn't empty
' according to it's length
If (length > 0) Then
ch.SetRange markRng.Start + length, markRng.Start + length + 1
Else
If (ch.text <> "<") Then
Set ch = ch.Next
End If
End If
Else
Set ch = ch.Next
End If
Loop Until ch Is Nothing
Set ch = Nothing
Exit Sub
Handler:
Debug.Print "Error in Replance Rng : " & Err.Description
End Sub
And modifySelect :
Private Sub modifySelect(text As String)
Options.ReplaceSelection = True
Selection.TypeText text
End Sub
with dicPatDat the dictionary.
Thank you again