Microsoft Word - infinite macro loop if ".text = " is added

Asked By hw chan on 12-May-12 06:22 AM

I want to change the first character after each bullet to lowercase. Don't understand why it loops infinitely
after the clause to update the paragraph ("myParagraph.Range.Text = ") is included. There is no infinite loop if the clause is commented out.

Dim myParagraph As Paragraph


If Len(Selection) = 1 Then Selection.WholeStory
For Each myParagraph In Selection.Paragraphs
    
    If (myParagraph.Range.ListFormat.ListType <> WdListType.wdListNoNumbering) Then
      bullet_txt = myParagraph.Range.Text
      new_text = LCase(Left(bullet_txt, 1)) & Mid(bullet_txt, 2)
      myParagraph.Range.Text = new_text
    End If

Next myParagraph
[)ia6l0 iii replied to hw chan on 12-May-12 10:36 AM
I am unsure about the vba code that you posted. However, once you have the selection (the first letters), you could just apply the Range.Case = wdLowerCase. 

Selection.Range.Case = wdLowerCase

Hope this helps.
hw chan replied to [)ia6l0 iii on 13-May-12 01:02 AM
Thanks a lot.

I take your advice and solve the problem as follows (even though I don't know why my original codes could cause an infinite loop).


Dim sel_range As Range
Dim myParagraph As Paragraph

If Len(Selection) = 1 Then Selection.WholeStory
Set sel_range = Selection.Range
    
For Each myParagraph In sel_range.Paragraphs
    
    If (myParagraph.Range.ListFormat.ListType <> WdListType.wdListNoNumbering) Then
      myParagraph.Range.Characters(1).Select
        Selection.Range.Case = wdLowerCase
    End If

Next myParagraph