PDA

View Full Version : newbie help?



RFArnold
10-13-2017, 01:33 PM
I am trying to create a Word (Mac Office 365) macro to toggle hidden text on with red text, and off returning to default text color.

This seems to work if the text is already hidden, but it doesn't do anything if not. Can someone please show me what I am doing wrong? Oh, and I am not trying to convert selected text... but change the text style at the insertion point for what I will type next.

Sub Comment()
'
' Comment Macro


If Selection.Font.Hidden = False Then
With Selection.Font
.Hidden = True
.Color = wdColorRed
End With
Else
With Selection.Font
.Hidden = False
.Color = wdColorAutomatic
End With
End If
End Sub
Sub EndComment()

THANK YOU!!

gmayor
10-13-2017, 08:51 PM
The colour change will only show if the hidden text is displayed in Word's options. If the text is not displayed it can't be selected, so you should create a character style and apply it to the text you want to toggle. Call it (say) "Hidden". Then it doesn't matter whether the text is displayed or not as you would change the style rather than the selection e.g.


With ActiveDocument.Styles("Hidden")
If .Font.Hidden = True Then
.Font.Hidden = False
.Font.Color = wdColorAutomatic
Else
.Font.Hidden = True
.Font.Color = wdColorRed 'as the font is hidden this is irrelevant unless the hidden text is displayed
End If
End With