Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Word VBA underlining problem.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robert - 29 Oct 2005 15:01 GMT
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
Robert - 29 Oct 2005 15:12 GMT
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
Tony Jollans - 29 Oct 2005 17:03 GMT
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

--
Enjoy,
Tony

> 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
Robert - 29 Oct 2005 18:32 GMT
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.
Tony Jollans - 29 Oct 2005 19:12 GMT
My pleasure!

--
Enjoy,
Tony

> Hello Tony,
> Thanks a lot for your kind and speedy response.
[quoted text clipped - 6 lines]
> Renewed thanks,
> Robert.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.