Word VBA underlining problem.

R

Robert

Hello NG friends,
I am trying to create a students' worksheet which identifies spelling
errors by underlining them (wavy) in the text. Each error word is then
followed by a short line of calculated length depending on the
error-word length. On this second line the student will write by hand
the eventual correction.

I cannot get the code below to produce the red wavy line under the word
followed by the (black/automatic) straight line for manuscript writing.
Any change needed for the second line is carried back to the first, and
vice-versa. (There is, or should be, a space between the two forms of
underlining.)

Could anyone please suggest a modification or improvement to make this
code do what I want? Thank you in advance.

Robert.

For Each blunder In ActiveDocument.SpellingErrors
blunder.Font.UnderlineColor = wdColorRed
blunder.Font.Underline = wdUnderlineSingle
'Change above to wdUnderlineWavy ???.
blunder.Words(1).Select
Selection.MoveEndWhile Cset:=" ", Count:=wdBackward
numchars = Selection.Characters.Count
Selection.MoveRight Unit:=wdCharacter
blunder.InsertAfter Text:=String(numchars * 2.5, Chr$(32)) & " "
i = i + 1 ' counter: total no of errors.
Next blunder
 
R

Robert

I forgot to mention that, with the present code, if the "manuscript"
line extends to the end of the line of text, then none of it is
displayed and there is nowhere for the correction to be written.

Sorry about that,
Robert
 
T

Tony Jollans

Hi Robert,

This should do it. It gets round the end-of-line problem by using
non-breaking spaces.

Dim blunder As Range
For Each blunder In ActiveDocument.SpellingErrors
With blunder
.Font.UnderlineColor = wdColorRed
.Font.Underline = wdUnderlineWavy
numchars = .Characters.Count
.Collapse wdCollapseEnd
.Text = String(numchars * 2.5, Chr$(160)) & " "
.Font.UnderlineColor = wdColorBlack
.Font.Underline = wdUnderlineSingle
End With
i = i + 1 ' counter: total no of errors.
Next blunder
 
R

Robert

Hello Tony,
Thanks a lot for your kind and speedy response.
Your coding works perfectly and has solved all the difficulties. Thank
you also for "tidying it up"; it looks more like the work of art that
good coding should.

Now I can get on with the rest of this project for my students.

Renewed thanks,
Robert.
 

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

Similar Threads


Top