Character Limits and Macro Spell Check

R

Rosiewednesday

I have a document with forms in it, and there are a few sections where I have
to limit the number of characters. So I inserted a Legacy Form Field text
box and then limited the characters through properties. However, when I try
to run a spell check macro, it is spell checking all of my other form fields
(these are RichText content controls), except for this one. I tried
inserting a RichText content control into the Legacy Form Field, but that
wouldn't work either. I just need to limit the characters people are typing
in this section and then spell check. To be honest, I don't even care if
it's protected or not. I've tried this macro:

Sub SCForm()
ActiveDocument.Unprotect
Selection.WholeStory
Selection.LanguageID = wdEnglishUS
ActiveDocument.CheckSpelling
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub

And this one:

Sub FormsSpellCheck()

' If document is protected, Unprotect it.
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="not2day"
End If

' Set the language for the document.
Selection.WholeStory
Selection.LanguageID = wdEnglishUS

' Perform Spelling/Grammar check.
If Options.CheckGrammarWithSpelling = True Then
ActiveDocument.CheckGrammar
Else
ActiveDocument.CheckSpelling
End If

' ReProtect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If

End Sub

The same thing happens. It checks everything but the character limiting
one. I also tried the one recommended on the MVP, and I couldn't get that
one to work at all. I wasn't quite sure what to copy/paste and what to
delete from that huge section.

Thanks in advance.
 
G

Graham Mayor

My own personal version of the form spell check macro is

Sub SpellCheckForm()
Dim i As Integer
Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""

End If

'check each formfield for spelling
For i = 1 To ActiveDocument.FormFields.Count
ActiveDocument.FormFields(i).Select
#If VBA6 Then
Selection.NoProofing = False
#End If
Selection.LanguageID = wdEnglishUK
Selection.Range.CheckSpelling
Next

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub

which will check the legacy form fields in a form. I assume from your use of
the term legacy form fields that this is a Word 2007 form. I would suggest
that you stick will all legacy form fields and protect the document for
forms. The new form tools have only been half heartedly included and are
insufficiently developed. The legacy fields on the other hand are well tried
and work.

If you want to fix the space in which the user can type, use a table cell of
fixed width and row height to contain the field. The remainder of the text
will not be moved and if too much text is entered the surplus will simply
'disappear'.


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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