none
Repeat Action to the end of a document RRS feed

  • Question

  • Hi,

    I am very new to the IT world.  I am working with creating a macro using VBA in Word 2007.  The objective of the macro is to highlight every 3rd line in yellow all the way through the document whether it is 10 lines, 10 paragraphs, or 10 pages long.  I am including the information that I have recorded on the macro so far which has allowed it to highlight the 1st line and skip down 2 lines to get to the 3rd line.  I am looking for the information that needs to go above and below the instructions that will allow it to perform the action until the end of a document. 

    I believe it is a "Do..Loop Until <condition>" type statement but I do not know what the condition is after until to be able to make it work.  I am guessing that this is a very entry level type programming question but I would appreciate any assistance!  Thank you for your help!


    Saturday, October 20, 2012 8:14 PM

All replies

  • Try this version:

    Sub HighlightEvery3()
        Dim lngLine As Long
        Dim lngStart As Long
        Application.ScreenUpdating = False
        Selection.HomeKey Unit:=wdStory
        Do
            lngStart = Selection.Start
            lngLine = lngLine + 1
            If lngLine Mod 3 = 1 Then
                ActiveDocument.Bookmarks("\line").Range.HighlightColorIndex = wdYellow
            End If
            Selection.MoveDown
        Loop Until Selection.Start = lngStart
        Application.ScreenUpdating = True
    End Sub


    Regards, Hans Vogelaar

    Saturday, October 20, 2012 8:35 PM