I am trying to create a VBA macro in Word that checks if a paragraph text consists of dots. If true, I want to add more dots until the whole line is filled with dots. The problem I am facing is that my macro enters an infinite loop.
I have the following code:
Sub Dots()
Application.ScreenUpdating = False
Dim doc As Document
Set doc = ActiveDocument
Dim paragraph As paragraph
For Each paragraph In doc.Paragraphs
If Left(paragraph.Range.Text, 6) = "......" Then
If Right(paragraph.Range.Text, 5) = "(NR)" & vbCr Then
paragraph.Range.Text = String(112, ".") & " (NR)" & vbCr
ElseIf Right(paragraph.Range.Text, 4) = "..." & vbCr Then
paragraph.Range.Text = String(122, ".") & vbCr
End If
End If
Next paragraph
Application.ScreenUpdating = True
End Sub
I suppose the problem is that, after changing the paragraph text with a vbCr in the end, the next loop analysis the same paragraph again. But if I don’t add a vbCr, the paragraph will be merged with the next one.
Any ideas, please?