Consulting

Results 1 to 2 of 2

Thread: newbie help?

  1. #1

    newbie help?

    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
    EndIf
    EndSub
    Sub EndComment()

    THANK YOU!!

  2. #2
    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
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •