A macro to replace check boxes

J

Josh

Does anyone have a macro that will replace every formfield check box
that is true with the capital letter "X"? I want the user to click a
commend button on the form and the macro will replace all the check
boxes that are true with a "x" and just delete the check boxes that
are false. I can probably do it myself if I use bookmarks and write
logic for each checkbox but i have over 300 on the word document! Any
help would be excellent, thank you!
 
B

Bear

Josh:

This should work. I'm not using the formfields collection because I'm
deleting the fields as I go. I start by unprotecting the document and end by
reprotecting it. Whether or not you reprotect is up to your application. --
Bear

Sub x()

Dim I As Integer

ActiveDocument.Unprotect

For I = ActiveDocument.FormFields.Count To 1 Step -1
With ActiveDocument.FormFields(I)
If .Type = wdFieldFormCheckBox Then
If .CheckBox.Value = True Then
.Range = "X"
Else
.Delete
End If
End If
End With
Next I

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=True

End Sub
 

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