petedw
07-25-2005, 07:36 AM
Alright guys!
Got a form with the following macro. As you can see it searches for all text in the style "HiddenRed" and then hides it.
Well....that's not entirely true, it runs up to a certain point and then stops with the error "Object variable or With block variable not set"
It runs through a protected section of the document fine without having to do anything, then goes into a unprotected section and hides some text in there. Once that is done, it throws up the above error.
The only thing left for it to do is to hide a few formfields(in a protected area) in the "HiddenRed" style.
Sub WorkInProtectedDoc()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then ActiveDocument.Unprotect Password:=""
Dim par As Paragraph
For Each par In ActiveDocument.Paragraphs
If par.Range.Style = "HiddenRed" Then
par.Range.Font.Hidden = True
End If
Next par
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End Sub
Cheers
Pete
Got a form with the following macro. As you can see it searches for all text in the style "HiddenRed" and then hides it.
Well....that's not entirely true, it runs up to a certain point and then stops with the error "Object variable or With block variable not set"
It runs through a protected section of the document fine without having to do anything, then goes into a unprotected section and hides some text in there. Once that is done, it throws up the above error.
The only thing left for it to do is to hide a few formfields(in a protected area) in the "HiddenRed" style.
Sub WorkInProtectedDoc()
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then ActiveDocument.Unprotect Password:=""
Dim par As Paragraph
For Each par In ActiveDocument.Paragraphs
If par.Range.Style = "HiddenRed" Then
par.Range.Font.Hidden = True
End If
Next par
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End Sub
Cheers
Pete