Share via

Warn before deleting hidden text

Anonymous
2022-01-25T20:05:32+00:00

I sometimes include hidden text in my document that I don't yet want a client to see but may be included in a later version of the document. Unfortunately, this hidden text often gets deleted while editing and deleting portions of normal (unhidden) text.

How do I get Word to warn me I am about to delete hidden text included in a selected block of text or using the delete or backspace keys?

Thanks.

Microsoft 365 and Office | Word | Other | 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

3 answers

Sort by: Most helpful
  1. Jay Freedman 207.7K Reputation points Volunteer Moderator
    2022-01-25T21:57:14+00:00

    Isn't there a macro that can give such a warning?

    Well, sort of. If you store the following macro in Normal.dotm (or another global template), it will pop up a message box and prevent the deletion if the selection includes both hidden and unhidden text.

    Sub EditClear() 
    
        With Selection 
    
            If .Font.Hidden = wdUndefined Then 
    
                MsgBox "This selection contains hidden text." 
    
                Exit Sub 
    
            Else 
    
                .Delete 
    
            End If 
    
        End With 
    
    End Sub
    

    This relies on the fact that when different characters in the selection have different values of the .Font.Hidden property, VBA figuratively throws up its hands and says "I can't put two values in the same variable at one time", and instead puts in the constant wdUndefined with the value 9999999.

    The name EditClear is required to make this work; it's the name of the command that runs when you press the Delete key. It would be possible to use a different name that isn't a command name, and assign some other key as a shortcut to run the macro, leaving the Delete key unaffected.

    There are several drawbacks to this method. One is that the macro doesn't run if you're using the Backspace key, so that would still delete any hidden text in the selection. If that's a big NO, the alternative is to get the free utility AutoHotKey from https://www.autohotkey.com and adapt the appropriate parts of the short script in Vinc199789's answer at https://stackoverflow.com/questions/56769417/run-word-macro-on-keypress-in-document .

    Another possible drawback is that if the selection consists entirely of hidden characters, it will be deleted, just the same as when the selection is all unhidden. Maybe this is what you want to happen.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2022-01-25T21:09:07+00:00

    Thanks Charles.

    Unfortunately, always showing formatting marks is not an option. All of those marks and hidden text are rather distracting and prevent a WYSWYG experience.

    Isn't there a macro that can give such a warning?

    Was this answer helpful?

    0 comments No comments
  3. Charles Kenyon 167.8K Reputation points Volunteer Moderator
    2022-01-25T20:53:00+00:00

    Briefly: If you keep it hidden, you can accidentally delete it. Period.

    To keep from doing this, when editing your documents, make it a practice to show the non-printing formatting marks. Always. It takes a mouse click and will include hidden text.

    Nonprinting Formatting Marks by Suzanne Barnhill, MVP

    Was this answer helpful?

    0 comments No comments