Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automating with the spell checker 2

Status
Not open for further replies.

Scanlan

Technical User
Sep 7, 2001
35
0
0
US
Hi all,

I need to make a macro that will basically run the spell checker and then change the font of any mis-spelled words so the words are red.

I want to do this without any user intervention, just run the macro and it magically turns the mis-spelled words to red.

I tried playing around with recording a macro and the only thing I learned was how to do was turn on the spell checker.

Does anyone have any ideas on how I might accomplish this? Anything I should read? Tips, pointers, and shoves in the right direction are all greatly appreciated.

Thanks,
Ann
 
for example
Excel:
Sub SpChColor()
Dim myRange, i As Range
Set myRange = Range("A1", ActiveSheet.Cells.SpecialCells(xlLastCell))
For Each i In myRange
If Not Application.CheckSpelling(i.Value, CustomDictionary:="CUSTOM.DIC", IgnoreUppercase:=False) Then
i.Font.ColorIndex = 3 'set font to red
End If
Next i
End Sub

or word:
Sub WordChech()
ActiveDocument.Bookmarks.Add Name:="temp", Range:=Selection.Range
For Each aWord In ActiveDocument.Words
If Not Application.CheckSpelling(aWord.Text, CustomDictionary:="CUSTOM.DIC", IgnoreUppercase:=False) Then
aWord.Font.Color = wdColorRed
End If
Next aWord
ActiveDocument.Bookmarks("temp").Select
ActiveDocument.Bookmarks("temp").Delete
End Sub

i hope it helps you
ide
 
OK, I've run into a slight wrinkle. Can you please help me convert this into VBScript to run in the browser?

The := construction chokes in the browser.

Thanks,
Ann
 
I don't know if there are more problems than the := construct when you're trying this in VBScript, but here's how to get rid of the :=

Using the Word example suggested by Ide:

Sub WordCheck()
ActiveDocument.Bookmarks.Add "temp", Selection.Range
For Each aWord In ActiveDocument.Words
If Not Application.CheckSpelling(aWord.Text, "CUSTOM.DIC", False) Then
aWord.Font.Color = wdColorRed
End If
Next aWord
ActiveDocument.Bookmarks("temp").Select
ActiveDocument.Bookmarks("temp").Delete
End Sub

Essentially, all you do is remove them and the preceding parameter designation. One word about this, however. You have to set the parameters in the exact order that VBA has them in. For example, for the line:

Application.CheckSpelling(aWord.Text, "CUSTOM.DIC", False)

if you don't want to set the custom dictionary, but do want to set the ignoreuppercase to false, the syntax would be:

Application.CheckSpelling(aWord.Text, , False)

All you have to do is type commas until you come to the parameter you want to set. The QuickInfo feature comes in very handy here. If you are using a VBScript editor that doesn't have QuickInfo, type your code in a VBA editor that does (such as Word), and then copy and paste it over.

-Christopher Thaxter
 
Thanks, the commas work, but it seems not to like the Next aWord direction.

I can comment out the aWord part and the script runs, but it doesn't do the spell checking.

Any ideas?

Thanks,
Ann
 
Got something that works in VBScript now. Thanks for the help.

Ann


app.Selection.TypeText testvar
app.Selection.TypeParagraph

WITH app
.Documents.Add
.ActiveDocument.BookMarks.Add "beginning", .Selection.Range
.Selection.TypeText testvar
.ActiveDocument.Bookmarks("beginning").Select
.ActiveDocument.Bookmarks("beginning").Delete
.Visible = True
END WITH

WITH app.ActiveDocument
.Bookmarks.Add "temp",app.Selection.Range
For Each aWord In .Words
If Not app.CheckSpelling(aWord.Text,"CUSTOM.DIC",False) Then
aWord.Font.Color = 255
aWord.Font.Bold = True
End If
Next
.Bookmarks("temp").Select
.Bookmarks("temp").Delete
END WITH
end sub
 
Okay. I was just working on a solution for you, so I'll give it to you anyway. It works in VBA, but I haven't tested it in VBS. I think it's much more straightforward even than the original example that was given to you.

Sub WordCheck()
Dim lngTotalWords As Long
Dim lngNextWord As Long

ActiveDocument.Bookmarks.Add "temp", Selection.Range

lngTotalWords = ActiveDocument.Words.Count

For lngNextWord = 1 To lngTotalWords
If Not Application.CheckSpelling(ActiveDocument.Words(lngNextWord).Text, _
"CUSTOM.DIC", False) Then
ActiveDocument.Words(lngNextWord).Font.Color = wdColorRed
End If
Next lngNextWord

ActiveDocument.Bookmarks("temp").Select
ActiveDocument.Bookmarks("temp").Delete
End Sub

-Christopher
 
Thank you. I love the way everyone is so willing to help out here. I will try out your solution when I have a chance and let you know how it worked.

I very much appreciate the help.

Thanks,
Ann
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top