PDA

View Full Version : Solved: Need help with two problems when spell checking forms...



Michael 514
08-26-2005, 09:36 AM
Hi guys!

Well, after yet another one-month hiatus, I am back to play with Word, and am enlisting help from all you experts out there. (The last week of the month is always my "Let's learn something about Office" week).

So, here is the deal. (I think what I am asking for can be done...!)

The background:
A - We sent protected forms to people, and in those forms, they can select drop-downs and enter free flowing text.

B - When they send these surveys back to us, I designed a macro (okay, I'll be honest.. it's a keystroke macro) that prepares these forms for our clients.

This little macro (which we call our "BEGIN!" macro) does some pretty simple things like change the view to Print View, Zoom to 100%, delete all paragraphs in our "Comment" style, update fields, and then... SPELL CHECK!

Now, here are two reasons why my survey reviewers HATE the spell check function:

(1)
It picks up spelling errors in the protected part of the document. We really don't want that. It catches all our 'misspelled' abbreviations, and so forth. Is there not a way to have it spellcheck just the part that the users use? (ie the text fields?

(2)
What would be even WAY cooler is if there was a way to ADD WORDS to the form's spell check "dictionary", if something like that exists. Of course, I know how to add words to my own Custom.dic, but is there way to have it pass over certain words in the form.

It's very annoying to see Word offer suggestions for worlds like "Tommy Hilfiger" to "Tommy Hilbertien" or "Tommy Hilaire". (It was my french reviewer who complained about this example.)

So.. Cliff's notes:
==============
1 - How can I add certain words to a form's spellcheck function, and/or tell it to ignore certain misspelled words

2 - How can I only spellcheck the text boxes, and not the form itself.

Thanks!

Mike

Michael 514
08-26-2005, 09:38 AM
Oh, by the way, here is the code we currently use for Spell check:


Sub EnglishSpell()
' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="1"
End If


' Set the language for the document.
Selection.WholeStory
Selection.LanguageID = wdEnglishUS
Selection.NoProofing = False
' Perform Spelling/Grammar check.
If Options.CheckGrammarWithSpelling = True Then
ActiveDocument.CheckSpelling
Else
ActiveDocument.CheckSpelling
End If

' ReProtect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True, Password:="1"
End If
End Sub

MOS MASTER
08-26-2005, 12:09 PM
Hi, :yes

I'm not sure I'm reading your question correct.

But it seams to me you have a fillin form that is made of Formfields?

And in that Form you only want to spell check the text input formfields and only the text input formfields?

Is that correct?

If so that is not that hard but I want to be sure on the question first. :moosegrin

Michael 514
08-26-2005, 12:12 PM
Hi there!

Thanks for writing back!

Yes, that is correct. Phase one is to ONLY spellcheck the formfields (I think that's what they are called.....! The gray places where the user can type his answers...!)

That's step #1!

And once that's out of they way, if we could have it skip or ignore or add certain words, then we are happy happy happy!

Thanks!

Mike

MOS MASTER
08-26-2005, 12:18 PM
Ok this one will spell check only the formfields in the activedocument
Sub myTotalCheckSpelling()
Dim iCnt As Integer

With Application.ActiveDocument
'Unprotect if protected
If .ProtectionType <> wdNoProtection Then _
.Unprotect Password:=""

'Loop all formfields
For iCnt = 1 To .FormFields.Count
'Select formfield
.FormFields(iCnt).Select

#If VBA6 Then
'Only Word > 2000
Selection.NoProofing = False
#End If
'Set Language
Selection.LanguageID = wdEnglishUK
'Run spell checker
Selection.Range.CheckSpelling
Next

'Reprotect without resetting the fields
.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:=""

MsgBox "Demo all fields spell check completed", vbInformation
End With
End Sub



HTH, http://vbaexpress.com/forum/images/smilies/elkgrin.gif

MOS MASTER
08-26-2005, 12:19 PM
O remember if you need to exclude some types of formfields the code has to be adapted...

But try it out first I'd say...! :moosegrin

Michael 514
08-26-2005, 04:36 PM
Excellent, Thank you very much!
I am going to try it!

I do have some questions to help me understand it:

1 - I see you loop through all "formfields". Are dropdown boxes also considered formfields, too? Normally, we have about 10 textual fields, with about 50 numeric and dropdown fields. Will your spellcheck cycle through all fifty fields, too? Is there a way to only check out textfields... just to improve performance? Or is this not required? I am just curious.

2 - I see you check only for Word > 2000. Many of our users use Word 2000. Is that going to be a problem? We don't let users use Word97, though.

Thank you!!!!

Mike

Anne Troy
08-26-2005, 06:21 PM
To NOT spell-check certain text in ANY document, simply select that text, and go to Tools-->Language-->Set language, and choose Do not check spelling or grammar. So, feasibly, you could Ctrl+A in your form, set the language, and then go UNCHECK it for the formfields you want to check language on. But you still need a macro to spellcheck in a protected form in 2000...

MOS MASTER
08-27-2005, 10:22 AM
Excellent, Thank you very much!
I am going to try it!

I do have some questions to help me understand it:

1 - I see you loop through all "formfields". Are dropdown boxes also considered formfields, too?
Yes they are! :yes


Normally, we have about 10 textual fields, with about 50 numeric and dropdown fields. Will your spellcheck cycle through all fifty fields, too? Is there a way to only check out textfields... just to improve performance? Or is this not required? I am just curious.
Yes it's possible to only check text input fields with the input set to text. (Cause you can have others too)

I'll post the code for that shortly.


2 - I see you check only for Word > 2000. Many of our users use Word 2000. Is that going to be a problem? We don't let users use Word97, though.
Mike
Yes I check for 2000 but you misunderstood that line.

I actualy check for VBA 6 which is 2000 and above (XP/2003)
In those versions you have to check another option to spellcheck.

So my code was meant to run on All versions of Office >97.

I'll post back later. :moosegrin

MOS MASTER
08-27-2005, 10:41 AM
Here's the changed code that will only spellcheck text formfields with the input set to string format:
Sub myTotalCheckSpelling()
Dim oFld As Word.FormField

With Application.ActiveDocument
'Unprotect if protected
If .ProtectionType <> wdNoProtection Then _
.Unprotect Password:=""
'Loop all formfields
For Each oFld In .FormFields()
' \\ Only check in Formfield textboxes that have textinput only
If oFld.Type = wdFieldFormTextInput And _
oFld.TextInput.Type = wdRegularText Then
With oFld.Range
#If VBA6 Then
'Only Word > 2000
.NoProofing = False
#End If
'Set Language
.LanguageID = wdEnglishUK
'Run spell checker
.CheckSpelling
End With
End If
Next
'Reprotect without resetting the fields
.Protect Type:=wdAllowOnlyFormFields, Noreset:=True, Password:=""
MsgBox "Demo all fields spell check completed", vbInformation
End With
End Sub


HTH, :moosegrin

Michael 514
08-28-2005, 09:51 AM
This looks like it's EXACTLY what I want!

...to only check the text fields!

Can't wait to try it.

As for my second query, is there also a way to tell Word to Ignore certain words that it considers "Misspelled".

I guess I am looking for a "Custom.dic" that "attaches" itself to the form. That would prove to be quite interesting...!

Thanks!

Mike

MOS MASTER
08-28-2005, 04:33 PM
This looks like it's EXACTLY what I want!

...to only check the text fields!

Can't wait to try it.

Glad you like it you're welcome! :yes



As for my second query, is there also a way to tell Word to Ignore certain words that it considers "Misspelled".

I guess I am looking for a "Custom.dic" that "attaches" itself to the form. That would prove to be quite interesting...!

Thanks!

Mike

Perhaps you could expand on that one Mike?

If you mean that you want to select some Words and mark them not to be spellchecked then please take another look at Anne's (Dreamboat) reply above. That would work that way.

If you need something else please specify in greater detail? :moosegrin

fumei
08-29-2005, 10:30 AM
Or use a custom dictionary say, named myFormfField.dic, specific for this document.

Dim dicCustom As Dictionary

Application.CustomDictionaries.ClearAll

Set dicCustom = Application.CustomDictionaries _
.Add(FileName:="C:\Program Files" _
& "\Microsoft Office\Office\myFormField.dic")
Application.CustomDictionaries.ActiveCustomDictionary = dicCustom

use that in the Document_Open event so it firing before spell check.....whatever...it depends on whether you want to hold the custom dic or not. In any case, you can build a specific custom dictionary that can be used in this specialized spellchecking ....if you want.

Michael 514
08-29-2005, 09:46 PM
ARGH... I posted an answer here and I got a page not found error!

All I wanted to say is thank you all!! I am going to try out the spell check of text fields only! That is going to be great if it works!

Second, for the Custom.Dic issue... What I really wanted was for a list of words to be sent WITH the forms. So the 1,500 people in the field won't have to worry about everytime it stops on retail words like NCO, Rounder, etc. But it's no big deal.

As long as our macro ONLY does Text Fields, that will be great.

I will keep you posted!

Thanks again!
Mike

MOS MASTER
08-30-2005, 11:42 AM
Hi Mike,
Glad we could help...you're welcome! :beerchug:

IMO Gerry already answered your question with a special Custom.dic for your document.

That would work it seams. :whistle: