Search for Checkbox Form field in a macro

G

Guest

I am trying to create a form that allows users to checkbox a section of text
for deletion in a macro. I have created checkboxes for each section and the
users check the box if they want keep that section. I am trying to write a
macro to remove all sections of text that were unchecked after they are
finished with the document. Is there an easy way to search for a checkbox
form field, and determine if it is checked or not? If there is, I can
highlight and delete up to the next section. I am not a VB programmer.
Anyone have any creative ideas? Thanks.
 
D

Dian D. Chapman, MVP

Note that you should post VBA question in one of the VBA groups in the
future.

But this code should get you started. It'll find all the checkboxes in
a doc and let you know, though a message, if they are checked and
their name. Just delete the MsgBox lines or put an apostrophe in front
of them so they will be ignored.

Sub FindCheckboxes()

Dim fld As FormField

For Each fld In ActiveDocument.FormFields
If fld.Type = wdFieldFormCheckBox Then
If fld.CheckBox.Value = True Then
'do something here to select/delete text
MsgBox "This checkbox is checked: " & fld.Name
Else
MsgBox "This checkbox is not checked: " & fld.Name
End If
End If
Next fld
End Sub

If you need help getting this code into your document, read this
TechTrax article:

Sharing Macros
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=166

Good luck...

Dian D. Chapman, Technical Consultant
Microsoft MVP, MOS Certified
Editor/TechTrax Ezine

Free MS Tutorials: http://www.mousetrax.com/techtrax
Free Word eBook: http://www.mousetrax.com/books.html
Optimize your business docs: http://www.mousetrax.com/consulting
Learn VBA the easy way: http://www.mousetrax.com/techcourses.html
 

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