PDA

View Full Version : Show/Hide text conditionally



beth_83
04-23-2006, 06:31 PM
I am trying to show / hide text according to the purpose of a letter. It is a mail merged letter that will then show additional text (including merge fields) based on a macro button that the user clicks.

I have tried this code but get an error message: Object variable or With block variable not set.

Dim lPara As Long
With ActiveDocument

For lPara = .Paragraphs.Count To 1 Step -1
With .Paragraphs(lPara)
If .Range.Style = "EmailStyle" Then
.Range.Font.Hidden = True
End If
End With
Next

End With

Any help with this would be greatly appreciated. Other code that I have tried is:

Sub ShowFaxStyle()
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("FaxStyle")
MsgBox Selection.Find.Style
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Hidden = False
End Sub

However the above code seems to do nothing!

Cheers
Beth

cssriraman
04-23-2006, 06:53 PM
Your code works fine without any errors.

Regards,

CS.

lucas
04-23-2006, 07:13 PM
In a quick look at this it hides text set to EmailStyle in 2003 for me also. no errors.

geekgirlau
04-26-2006, 07:14 PM
Thanks for the tip guys... Not sure what happened on my machine but I have decided to use the following code:

Dim oStyle As Style
Set oStyle = ActiveDocument.Styles("FaxStyle")
oStyle.Font.Hidden = True

Beth

geekgirlau
04-26-2006, 07:16 PM
Hi Beth,

I've split your posts (previous post from Beth shown above) to start a new topic - you'll get a much better response this way rather than posting a new question in the same thread.