formatting "misspelled" words macro

F

fogharty

I'm working (still) on a Latin course.

One of the things I did was to copy and paste the original working Word
5 documents into Word 2004 as unformatted text so that I could insert
the correct Unicode characters. See original posts here.

<http://groups.google.com/group/micr...8c5b713ec?q=fogharty&rnum=11#ca5f0b18c5b713ec">

Of course, I lost all my formatting when I did this, all my bolding and
italics. Since all the Latin words need to be italicized, and my
document/dictionary thinks all these words are misspellings, I was
wondering if there was a way to write a macro to find all "misspelled"
words and format them.

I searched around these groups and the MVPS site, and found a few
macros that I thought I could adapt. Unfortunately I keep getting
syntax errors and I can't see what's wrong.

Can someone help me with the VBA script?

Thanks

=========================
Here is one script:
=========================

Sub latin_words()
'
' latin_words Macro
' Macro recorded 7/14/06 by fogharty
'
Dim spErr As Object
For Each spErr In ActiveDocument.Range.SpellingErrors
spErr.Font.Color = wdColorDarkRed
spErr.Font.Italic = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub


=========================
Here is another:
=========================

Sub latin_words()
'
' latin_words Macro
' Macro recorded 7/14/06 by fogharty
'

Dim oWord As Range
Dim StoryRange As Range

For Each StoryRange In ActiveDocument.StoryRanges
Application.CheckSpelling Word:=StoryRange
For Each oWord In StoryRange.Words
If Not Application.CheckSpelling(Word:=oWord.Text) Then
oWord.HighlightColorIndex = wdYellow
End If
Next oWord
Next StoryRange

End Sub
 
J

John McGhie [MVP - Word and Word Macintosh]

Sorry, I don't have time to do this right now. However. A "SpellingError"
is a range object, so I would try the following tweaks to your first script:

Sub latin_words()
'
' latin_words Macro
' Macro recorded 7/14/06 by fogharty
'
Dim spErr As Range
For Each spErr In ActiveDocument.Range.SpellingErrors
with spErr
.Font.Color = wdColorDarkRed
.Font.Italic = True
.NoProofing = True
End With
next spErr

End Sub

I would never risk using Selection.Find.Execute Replace:=wdReplaceAll in a
macro unless I have explicitly loaded the Find and Replace objects in the
same macro. Find and Replace both contain whatever they were last set to
each time they were used after the first use in a Word session: it is not
safe to reply on them being in any particular state, you must set them.

In this macro, you do not need them anyway, unless there is something you
are not telling me about!

Note that Check Spelling while Typing must be on for this macro to work
(i.e. There must BE some spelling errors in the document for it to operate
upon).

You would normally also add the "noproofing" property to latin text to
prevent the spelling checker stopping on it every time.

I would be more likely to create a character style with the colour, italic
and language=no proofing properties then use the macro to apply the style to
each spelling error.

Cheers

I'm working (still) on a Latin course.

One of the things I did was to copy and paste the original working Word
5 documents into Word 2004 as unformatted text so that I could insert
the correct Unicode characters. See original posts here.

<http://groups.google.com/group/microsoft.public.mac.office.word/browse_frm/th
read/c0fe9e733adcf834/ca5f0b18c5b713ec?q=fogharty&rnum=11#ca5f0b18c5b713ec">

Of course, I lost all my formatting when I did this, all my bolding and
italics. Since all the Latin words need to be italicized, and my
document/dictionary thinks all these words are misspellings, I was
wondering if there was a way to write a macro to find all "misspelled"
words and format them.

I searched around these groups and the MVPS site, and found a few
macros that I thought I could adapt. Unfortunately I keep getting
syntax errors and I can't see what's wrong.

Can someone help me with the VBA script?

Thanks

=========================
Here is one script:
=========================

Sub latin_words()
'
' latin_words Macro
' Macro recorded 7/14/06 by fogharty
'
Dim spErr As Object
For Each spErr In ActiveDocument.Range.SpellingErrors
spErr.Font.Color = wdColorDarkRed
spErr.Font.Italic = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub


=========================
Here is another:
=========================

Sub latin_words()
'
' latin_words Macro
' Macro recorded 7/14/06 by fogharty
'

Dim oWord As Range
Dim StoryRange As Range

For Each StoryRange In ActiveDocument.StoryRanges
Application.CheckSpelling Word:=StoryRange
For Each oWord In StoryRange.Words
If Not Application.CheckSpelling(Word:=oWord.Text) Then
oWord.HighlightColorIndex = wdYellow
End If
Next oWord
Next StoryRange

End Sub

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
F

fogharty

Sub latin_words()
'
' latin_words Macro
' Macro recorded 7/14/06 by fogharty
'
Dim spErr As Range
For Each spErr In ActiveDocument.Range.SpellingErrors
with spErr
.Font.Color = wdColorDarkRed
.Font.Italic = True
.NoProofing = True
End With
next spErr

End Sub


Sorry John,
I keep getting a syntax error message.
I'll keep plugging away at it.
fogharty
 
J

JE McGimpsey

I keep getting a syntax error message.
I'll keep plugging away at it.

I copied and pasted John's macro into a module, and it works fine with
no syntax errors.

Since you're using googlegroups, I suspect the problem is that the white
space used to indent the code is being copied as non-breaking spaces by
your browser when you paste it into the Visual Basic Editor (VBE).

Try deleting all the whitespace at the beginning of each line. You can
use tabs or space characters in the VBE to restore the indenting if you
wish (it's not necessary, but it helps with readability).
 
F

fogharty

JE said:
I copied and pasted John's macro into a module, and it works fine with
no syntax errors.

Since you're using googlegroups, I suspect the problem is that the white
space used to indent the code is being copied as non-breaking spaces by
your browser when you paste it into the Visual Basic Editor (VBE).

Try deleting all the whitespace at the beginning of each line. You can
use tabs or space characters in the VBE to restore the indenting if you
wish (it's not necessary, but it helps with readability).


I'll try that, thanks!
I also came up with something that sorta works, but it took almost 20
minutes to do a 30 page document, so I'll see if John's script? code?
will work better.

This is the script I came up with (after much searching):

Sub FormatSpellingErrors()

Dim spErr As Range
For Each spErr In ActiveDocument.Range.SpellingErrors
spErr.Font.Italic = True
Next
End Sub
 
F

fogharty

JE said:
I copied and pasted John's macro into a module, and it works fine with
no syntax errors.

Since you're using googlegroups, I suspect the problem is that the white
space used to indent the code is being copied as non-breaking spaces by
your browser when you paste it into the Visual Basic Editor (VBE).

Try deleting all the whitespace at the beginning of each line. You can
use tabs or space characters in the VBE to restore the indenting if you
wish (it's not necessary, but it helps with readability).

JE, I did as you suggested, and it worked! John's script runs fine,
although it still takes a bit of time.

Thanks for all your help, both of you. This has saved me a lot of time
and I think will come in very handy for other documents that contain a
number of non-English words.
 

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