CodeIsLaw
CodeIsLaw

Reputation: 345

Making an area un-editable using a checkbox

I have a word-document and want to make a specific area uneditable (greyed out) if the value of a checkbox is true. My problem is that there are some errors, which I am unable to fix it by myself, hopefully you can help me out with it.

Sub checkBoxStatus()

'declare variables
Dim cb3Y As CheckBox
Dim cb3N As CheckBox

Set cb3Y = ActiveDocument.FormFields(1).CheckBox

cb3Y.Value = False 'just needed this for debugging, to see if I got the right checkbox

End Sub

I got an error message all the time when running this code fragment. "Runtime Error '5941' The Requested Member of Collection Does Not Exist". Unfortunately I don't know where I can edit the id of the right checkbox I need.

Upvotes: 0

Views: 37

Answers (1)

macropod
macropod

Reputation: 13515

There is no CheckBox collection. Use something like:

Sub checkBoxStatus()
With ActiveDocument
  If .FormFields(1).CheckBox.Value = True Then
    ' code for true here
  Else
    ' code for false here
  End If
End With
End Sub

Upvotes: 1

Related Questions