Creating a highlighting macro

N

newtechieC

How do you create a macro in Word 07, using Windows XP, that will highlight
every third line of text in a document, and that will prompt the user for the
number of lines to highlight and then use some shading to highlight every
third line. Also, to prompt the user for the number of lines to highlight and
present the user with a choice of 3 different highlighting options (perhaps 3
colors?).
 
G

Greg Maxey

To hightlight every third line you could uses something like this:

Sub ScratchMacro()
Dim bEndFlag As Boolean
bEndFlag = False
ActiveDocument.Range(0, 0).Select
Do Until bEndFlag
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
If Selection.End = ActiveDocument.Range.End Then bEndFlag = True
Selection.Range.HighlightColorIndex = wdYellow
Selection.Collapse wdCollapseStart
Selection.MoveDown wdLine, 3
Loop
End Sub
How do you create a macro in Word 07, using Windows XP, that will
highlight every third line of text in a document, and that will
prompt the user for the number of lines to highlight and then use
some shading to highlight every third line. Also, to prompt the user
for the number of lines to highlight and present the user with a
choice of 3 different highlighting options (perhaps 3 colors?).

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the
strong man stumbles, or where the doer of deeds could have done them
better. The credit belongs to the man in the arena, whose face is
marred by dust and sweat and blood, who strives valiantly...who knows
the great enthusiasms, the great devotions, who spends himself in a
worthy cause, who at the best knows in the end the triumph of high
achievement, and who at the worst, if he fails, at least fails while
daring greatly, so that his place shall never be with those cold and
timid souls who have never known neither victory nor defeat." - TR
 
N

newtechieC

Yes! Greg you so rock. I did tweek it a bit, because when it got to the end
of the document the macro tried to keep going. So what I did what add a few
things and tested it. This is what I did:

Sub highlight ()
Dim bEndFlag As Boolean
bEndFlag = False
ActiveDocument.Range(0, 0).Select
Do Until Selection.End=ActiveDocument.Content.End-1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
If Selection.End = ActiveDocument.Range.End Then bEndFlag = True
Selection.Range.HighlightColorIndex = wdYellow
Selection.Collapse wdCollapseStart
Selection.MoveDown wdLine, 3
Loop
End Sub

Thank you again so much Greg!!!
 
G

Greg Maxey

Great. Glad you got something to work as you wished.

Yes! Greg you so rock. I did tweek it a bit, because when it got to
the end of the document the macro tried to keep going. So what I did
what add a few things and tested it. This is what I did:

Sub highlight ()
Dim bEndFlag As Boolean
bEndFlag = False
ActiveDocument.Range(0, 0).Select
Do Until Selection.End=ActiveDocument.Content.End-1
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
If Selection.End = ActiveDocument.Range.End Then bEndFlag = True
Selection.Range.HighlightColorIndex = wdYellow
Selection.Collapse wdCollapseStart
Selection.MoveDown wdLine, 3
Loop
End Sub

Thank you again so much Greg!!!

--
Greg Maxey

See my web site http://gregmaxey.mvps.org
for an eclectic collection of Word Tips.

"It is not the critic who counts, not the man who points out how the
strong man stumbles, or where the doer of deeds could have done them
better. The credit belongs to the man in the arena, whose face is
marred by dust and sweat and blood, who strives valiantly...who knows
the great enthusiasms, the great devotions, who spends himself in a
worthy cause, who at the best knows in the end the triumph of high
achievement, and who at the worst, if he fails, at least fails while
daring greatly, so that his place shall never be with those cold and
timid souls who have never known neither victory nor defeat." - TR
 
M

macropod

Hi newtechieC,

Just be aware that, because Word uses the active print driver to lay out the document, changing printers could mess up all your
highlighting by changing where each line ends ...
 
N

newtechieC

Thanks macropod, but I only changed the nam of the macro, not the printer. I
did test it out and it work without going wacky on me so i'm happy with that.
But if you have any ideas for anding a prompt for the user to choose between
3 different highlight colors _and_ prompt the user to choose how many lines
to highlight I would be most apprecative.
--
Christine NF


macropod said:
Hi newtechieC,

Just be aware that, because Word uses the active print driver to lay out the document, changing printers could mess up all your
highlighting by changing where each line ends ...

--
Cheers
macropod
[Microsoft MVP - Word]


newtechieC said:
How do you create a macro in Word 07, using Windows XP, that will highlight
every third line of text in a document, and that will prompt the user for the
number of lines to highlight and then use some shading to highlight every
third line. Also, to prompt the user for the number of lines to highlight and
present the user with a choice of 3 different highlighting options (perhaps 3
colors?).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top