Delete Text Not Hyperlinked Test (Nov 3 2021).docmThe attached macro is intended to search for user-entered text and remove all occurrences of it in the active document if it is not hyperlinked.
The only way I know how to test text for links is to query if it has a link address or display text, and since this causes an error if no link is present, I trap that error and use it to perform the deletion.
What I have so far works perfectly as long as I either leave the default text in the input box as is, or retype it with the same case. If I change the case of just one letter in the input box, the macro doesn’t find it and stops. Even though I have .MatchCase = False, and even if I add Option Compare Text, this search is still case sensitive, and nothing I've tried works.
Can someone help me with getting this to find all occurrences of the text, delete those with links, regardless of the case of the entered search text?
The attached document that contains the macro has five instances of “Add as Friend Send Message”, two of which have links and should be preserved while the other three should be removed. First you can run it as is with the default search text to see how it is supposed to work, regardless of case, and then close it without saving and run it again, but change the case of the input box, and you’ll see it fails to find any of the same occurrences.