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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word 97 Selection of only form fields in macro ALL form fields

Status
Not open for further replies.

mastry

Programmer
Dec 27, 1999
5
US
I am trying to spell check a document with many form fields. In a macro I need to &quot;select&quot; all of the form fields at once and then complete the spell check. I am able to select formfields one at a time and loop through them all, but the user has to press the NO key to move between each form field. This is the code I am currenty using. I would like to find a way to skip the looping routine and select all of the form fields, without selecting any of the non form field text. ie. not using SELECTION.WHOLESTORY.<br>
<br>
Here is the code I am currently using.<br>
<br>
Sub FormsSpellCheck()<br>
' If document is protected, Unprotect it.<br>
If ActiveDocument.ProtectionType &lt;&gt; wdNoProtection Then<br>
ActiveDocument.Unprotect Password:=&quot;&quot;<br>
End If<br>
<br>
Dim aStory As Range<br>
Dim aField As FormField<br>
For Each aStory In ActiveDocument.StoryRanges<br>
For Each aField In aStory.FormFields<br>
aField.Select<br>
<br>
' Set the language for the document and spell check selection.<br>
Selection.Select<br>
Selection.LanguageID = wdEnglishUS<br>
' Perform Spelling/Grammar check.<br>
If Options.CheckGrammarWithSpelling = True Then<br>
ActiveDocument.CheckGrammar<br>
Else<br>
ActiveDocument.CheckSpelling<br>
End If<br>
Next aField<br>
Next aStory<br>
' ReProtect the document.<br>
If ActiveDocument.ProtectionType = wdNoProtection Then<br>
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True<br>
End If<br>
<br>
End Sub<br>
<br>
<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top