Share via

Visual Basic Command to Toggle Underlining

Anonymous
2022-03-06T12:09:50+00:00

The following commands toggle boldface and italics of a selected text:

Selection.Font.Bold = wdToggle

Selection.Font.Italic = wdToggle

However, the following command does not toggle underlining:

Selection.Font.Underline = wdToggle

Does anyone know what command can be used to toggle underlining?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Stefan Blom 342.6K Reputation points MVP Volunteer Moderator
2022-03-06T12:21:52+00:00

Word supports multiple underline formats, and therefore there is no simple toggle available.

Using an IF statement, you can construct a macro that toggles between single underline and no underline at all:

    If Selection.Font.Underline = wdUnderlineNone Then 

        Selection.Font.Underline = wdUnderlineSingle 

    Else 

        Selection.Font.Underline = wdUnderlineNone 

    End If

Was this answer helpful?

4 people found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Stefan Blom 342.6K Reputation points MVP Volunteer Moderator
    2022-03-07T14:14:54+00:00

    I'm glad I could help.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-03-07T07:59:27+00:00

    Word supports multiple underline formats, and therefore there is no simple toggle available.

    Using an IF statement, you can construct a macro that toggles between single underline and no underline at all:

        If Selection.Font.Underline = wdUnderlineNone Then 
    
    
    
            Selection.Font.Underline = wdUnderlineSingle 
    
    
    
        Else 
    
    
    
            Selection.Font.Underline = wdUnderlineNone 
    
    
    
        End If
    

    Thank you. This is a good solution.

    Was this answer helpful?

    0 comments No comments