Deleting empty formfields

M

Mark

I am using Word 2003, can someone assist me with some code which looks
through a document and deletes all the formfields that are not populated.

Thanks in advance
 
J

Jean-Guy Marcil

Mark was telling us:
Mark nous racontait que :
I am using Word 2003, can someone assist me with some code which looks
through a document and deletes all the formfields that are not
populated.

Thanks in advance

Here is a little something to get you going. The following assumes that the
first choice in a formfield dropdown is the default one, such as "Choose" or
"Select" or "Pick something!"
As for text input fields, they will be deleted if their content is equal to
the default values, which might be nothing or any text used when designing
the form, such as "Write your name here."

'_______________________________________
Option Explicit
'_______________________________________
Sub DelEmptyFF()

Dim myFFs As FormFields
Dim i As Long

Set myFFs = ActiveDocument.FormFields

ActiveDocument.Unprotect

For i = myFFs.Count To 1 Step -1
Select Case myFFs(i).Type
Case wdFieldFormTextInput
If myFFs(i).Result = myFFs(i).TextInput.Default Then _
myFFs(i).Range.Delete
Case wdFieldFormCheckBox
If myFFs(i).CheckBox.Value = False Then _
myFFs(i).Range.Delete
Case wdFieldFormDropDown
If myFFs(i).DropDown.Value = 1 Then _
myFFs(i).Range.Delete
End Select
Next

ActiveDocument.Protect wdAllowOnlyFormFields, True

End Sub
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
[email protected]
Word MVP site: http://www.word.mvps.org
 
Top