Using wildcards in the custom.dic

D

Dan-_78

Hello,
I want to add an entry to the custom.dic that will cause the spell checker
to ignore the spelling of any word that has the underscore character in it. I
think I could do this using the wildcard character, but I can't seem to find
a 'wildcard' that works.

For example, I want Word to NOT check the spelling of any of the following
strings: id_enable, grep_should_pass, clk_is_blocked, cntr_load_en, and so
forth.

I've tried adding *_* to custom.dic and ?_? but the spell checker still
insists on saying that any word with an underscore is mis-spelled.

Any suggestions on how to fix this? Is there an approach to solving this
other than using an entry in the custom.dic?

Thanks,
Dan
 
J

Jay Freedman

The custom dictionary can't do anything like this -- it's just a list of
specific strings that the speller consults before labeling something as an
error.

You can do a wildcard Find/Replace to achieve this. First click the More
button in the Replace dialog and check the box for "Use wildcards". In the
Find What box, enter the expression

<*_*>

which represents any word containing an underscore. In the Replace With box,
enter

^&

which represents "the text that was found". While the cursor is still in the
Replace With box, click the Format button, choose Language from the menu,
and put a check mark in the "Do not check spelling or grammar" box. Finally,
click the Replace All button. Every work that contains an underscore will be
marked to be ignored by the speller.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
D

Dan-_78

Thanks Jay, that is something that I can do on a document by document basis.

But, is there any way to automate this? Maybe a macro or something that
performs this sequence when I tell it to? Or better yet, something that
performs this sequence every time I open a document?

I don't know much about Word macros in all honesty. In gvim I could use
something like an autocmd to run the macro everytime I open a document. I'm
guessing Word also has something similar that will run everytime I open a
document?

I'll hunt around for education about Word macros, but if this is a 'no
brainer' for some of you Word wizards, guidance would be appreciated.

Regards,
Dan
 
J

Jay Freedman

Oops, I should have checked a little closer. Because of a quirk of the *
wildcard, that search term would mark the entire document as "do not check".
Instead, use this one:

<[A-Za-z]@_[A-Za-z]@>

followed by another pass with this one to catch the last part of any item
that contains more than one underscore:

_*>

or, if the underscored words could contain numbers, use this as the first
pass:

<[A-Za-z0-9]@_[A-Za-z0-9]@>
 
J

Jay Freedman

Here's a macro that does the same thing as my other post, which crossed yours.

Sub NonSpellUnderscores()
Dim oRg As Range
Set oRg = ActiveDocument.Range
With oRg.Find
.MatchWildcards = True
.Text = "<[A-Za-z]@_[A-Za-z]@>"
.Replacement.Text = "^&"
.Replacement.NoProofing = True
.Execute Replace:=wdReplaceAll
End With
Set oRg = ActiveDocument.Range
With oRg.Find
.MatchWildcards = True
.Text = "_*>"
.Replacement.Text = "^&"
.Replacement.NoProofing = True
.Execute Replace:=wdReplaceAll
End With
ActiveDocument.SpellingChecked = False
ActiveDocument.CheckSpelling
End Sub

See http://www.gmayor.com/installing_macro.htm if you need instructions on what
to do with it.

To make it run every time you open any document, place the macro in the
Normal.dot template and change the first line from Sub NonSpellUnderscores() to

Sub AutoOpen()

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 

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