If you put the cities in text form fields (set the city name as the default
text and uncheck the box 'fill in enabled') the following macro run on exit
from the last check box field assumes three cities, with three check boxes
Check1 to Check3
and three associated text fields Text1 to Text3. When the macro runs, each
check box value is read and if the box is unchecked, both it and its
associated text box are formatted as hidden, so effectively disappear from
the document.
http://www.gmayor.com/installing_macro.htm
Sub ClearCities()
Dim oFld As FormFields
Set oFld = ActiveDocument.FormFields
Dim bProtected As Boolean
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Process each set of fields
If oFld("Check1").CheckBox.Value = False Then
oFld("Text1").Select
Selection.Font.Hidden = True
oFld("Check1").Select
Selection.Font.Hidden = True
End If
If oFld("Check2").CheckBox.Value = False Then
oFld("Text2").Select
Selection.Font.Hidden = True
oFld("Check2").Select
Selection.Font.Hidden = True
End If
If oFld("Check3").CheckBox.Value = False Then
oFld("Text3").Select
Selection.Font.Hidden = True
oFld("Check3").Select
Selection.Font.Hidden = True
End If
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub
The following macro will reset the fields to make them visible again
Sub ResetFormFields()
Dim bProtected As Boolean
Dim oFld As FormFields
Dim i As Long
Set oFld = ActiveDocument.FormFields
'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'Format all fields as not hidden
For i = 1 To oFld.Count
oFld(i).Select
Selection.Font.Hidden = False
Next
'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site
www.gmayor.com
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>