none
Loop question RRS feed

  • Question

  • The following snip it from my macro that works. But I want it to loop through 35 times

     

    PC1 As String, PC2 As String, and so on….

     

     

    If oBMs("CB1").Range.Font.Color = wdColorAutomatic Then

        PC1 = False

    Else

        PC1 = True

    End If

     

    I tried this but it doesn’t work:

     

    For i = 1 To 35

      If oBMs("CB" & i).Range.Font.Color = wdColorAutomatic Then

        ActiveDocument.Variables("PC" & i) = False

      Else

        ActiveDocument.Variables("PC" & i) = True

      End If

    Next i

     

    What am I doing wrong?

     

    Friday, January 14, 2011 8:18 PM

Answers

  • Use

    Dim strBMName as String
    For i = 1 To 35
       strBMName = "CB" & i
       With ActiveDocument
            If .Bookmarks(strBMName).Range.Font.Color = wdColorAutomatic Then
               .Variables("PC" & i) = False
            Else
               .Variables("PC" & i) = True
            End If
       End With
    Next i


    Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "fuzzhead58" wrote in message news:57d004e7-d406-4d3d-9784-e90e6f58c6fd@communitybridge.codeplex.com...

    The following snip it from my macro that works. But I want it to loop through 35 times



    PC1 As String, PC2 As String, and so on….





    If oBMs("CB1").Range.Font.Color = wdColorAutomatic Then

       PC1 = False

    Else

       PC1 = True

    End If



    I tried this but it doesn’t work:



    For i = 1 To 35

     If oBMs("CB" & i).Range.Font.Color = wdColorAutomatic Then

       ActiveDocument.Variables("PC" & i) = False

     Else

       ActiveDocument.Variables("PC" & i) = True

     End If

    Next i



    What am I doing wrong?


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by Bessie Zhao Wednesday, January 19, 2011 5:48 AM
    • Unmarked as answer by fuzzhead58 Tuesday, September 9, 2014 3:07 PM
    • Marked as answer by fuzzhead58 Tuesday, September 9, 2014 3:08 PM
    Saturday, January 15, 2011 6:00 AM