Hi Folks - real beginner here with VBA in word, surrounded by technophobes!
Am trying to do a protected form letter. Users enter details in form fields
which populate through the letter using Cross references. There is one
paragraph that I need to insert/remove based on the user checking a checkbox.
(Checked = include the text, unchecked = exclude). My code is below, but I
get a 'Runtime Error 5941 - The requested member of the collection does not
exist.'
I know this is something simple I've done by not structuring the code
correctly...but can't seem to fix it.
Can anyone offer any advice?
- QualityCheck is the Formfield(Checkbox) Name
- QualityWords is the bookbark containing the hidden text.
If the document is password protected, so I need to unprotect to unhide the
text and re-protect again after it's run?
Sub UnhideQualityText()
Dim QualityCheck As String
If FormFields(QualityCheck).CheckBox.Value = False Then
ActiveDocument.Bookmarks("QualityWords").Range.Font.Hidden = True
Else
ActiveDocument.Bookmarks("QualityWords").Range.Font.Hidden = False
End If
End Sub
Appreciate any advice.....
Thanks,
John.
Jezebel - 30 Aug 2006 06:29 GMT
The mistake in your code is that you declare the string variable
QualityCheck but don't assign it a value. So the line
FormFields(QualityCheck) is effectively FormFields("")
Try --
ActiveDocument.Bookmarks("QualityWords").Range.Font.Hidden = not
FormFields("QualityCheck").CheckBox.Value
> Hi Folks - real beginner here with VBA in word, surrounded by
> technophobes!
[quoted text clipped - 32 lines]
> Thanks,
> John.
JohnatSydney - 30 Aug 2006 23:54 GMT
Thanks J - that's got it! Appreciate your expert advice.
Regards,
JOHN.
> The mistake in your code is that you declare the string variable
> QualityCheck but don't assign it a value. So the line
[quoted text clipped - 41 lines]
> > Thanks,
> > John.