A family of Microsoft word processing software products for creating web, email, and print documents.
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.