Microsoft Office Forums Word VBA Help

Go Back   Microsoft Office Forums > >

Thread Tools Display Modes
Old 06-04-2019, 07:40 AM
dannyZ dannyZ is offline Word VBA Help Windows 10 Word VBA Help Office 2019
Word VBA Help
Join Date: Jun 2019
Posts: 1
dannyZ is on a distinguished road
Default Word VBA Help

Hi All,

I'm a very noob user when it comes to word macros/VBA so I hope someone could help me without it being too much trouble.

I need a macro that will highlight every 3rd line throughout a word document.

Also if it could prompt the user to start from the beginning of the document or start from where the cursor is.

I really have no idea where to start with this and I'm hoping for some help with this if possible.
Reply With Quote
Old 06-04-2019, 04:29 PM
Guessed's Avatar
Guessed Guessed is offline Word VBA Help Windows 10 Word VBA Help Office 2016
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,379
Guessed is a jewel in the roughGuessed is a jewel in the roughGuessed is a jewel in the roughGuessed is a jewel in the rough


This sounds a lot like a learning task assigned by a teacher so I don't want to just give you the answer.

The first thing to discuss is the fact that 'line' is not a good term to use since it is not a fixed or easily testable thing in Word. You should be working with 'paragraphs' instead of 'lines'.

To get started, try recording a macro of you applying highlighting to a selected paragraph of text. Once you have that minimal code, post it here and we can point you to how to start performing the other steps.
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Old 06-06-2019, 12:06 PM
gmaxey gmaxey is offline Word VBA Help Windows 10 Word VBA Help Office 2016
Word MVP 2003-2009
Join Date: May 2010
Location: Marble, NC
Posts: 967
gmaxey will become famous soon enoughgmaxey will become famous soon enough


I'm not going to give you the whole fish and this is a bit clunky, but you can use selection and the wdLine unit to get this started:

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oRng As Range
Dim lngCount As Long
Dim bExit As Boolean
  Set oRng = ActiveDocument.Range
  oRng.Collapse wdCollapseStart
  Application.ScreenUpdating = False
  On Error GoTo Err_Exit
  Selection.MoveDown wdLine, 2
  Selection.Range.HighlightColorIndex = wdBrightGreen
  Selection.Collapse wdCollapseEnd
    lngCount = 0
      Selection.MoveDown wdLine, 1
      lngCount = lngCount + 1
      If Selection.Range.End + 1 = ActiveDocument.Range.End Then bExit = True
      If bExit Then Exit Do
    If lngCount = 2 Then
      Selection.Range.HighlightColorIndex = wdBrightGreen
      Selection.Collapse wdCollapseEnd
    End If
    If bExit Then Exit Do
  Application.ScreenUpdating = True
  Exit Sub
  Resume lbl_Exit
End Sub
Greg Maxey
Please visit my web site at
Reply With Quote

Thread Tools
Display Modes

All times are GMT -7. The time now is 12:17 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd. is not affiliated with Microsoft