PDA

View Full Version : Word 2007 checkbox loop



paulo_otw
04-28-2010, 08:37 AM
Hi,
I'm new to using VBA in Word but have some (self taught) knowledge of VBA in Excel so please be gentle with me :)

I've in herited a master document used for producing our company training manualls. In the docx there are 20+ check boxes each with its own code attached for deleting the relevant section / bookmark from the docx.


Private Sub CheckBox1_Click()
If CheckBox1.Value = False Then
ActiveDocument.Bookmarks("Unit_1").Range.Delete
End If
End Sub

I'd like to take this a step (or 2) further:
hide the section rather than delete it
save space and tidy the code so that there is just 1 maco that loops through something along the lines of:
for i = 1 to 20
if "checkbox & i".value = false then
ActiveDocument.Bookmarks("Unit_" & i).Range.hide
i=i+1
else
i=i+1
end if
next i
please forgive coding just a quick example / thought on how it could / would / might look.

all help is welcomed
Paulo