I have again tested the code (repeated below) and it does what it is supposed to do and the completion message (not part of the original) works where it is now placed.
If the macro doesn't do anything, it is likely to be that the criteria set in the code does not match what is in the document. Post a sample document in which it does not work.
Quote:
Originally Posted by jeffreybrown
not sure why you even need Exit Sub as there is nothing left to do or skip.
|
It's a personal programming foible, that I use will all my code, and which is primarily used in conjunction with error handling routines, though in this instance there is no such routine.
Code:
Sub Delete_Underscores()
' 'Graham Mayor - http://www.gmayor.com - Last updated - 03 Oct 2018
'
' Delete_Underscores Macro
' Will delete all underscores in Document except in Mail addresses (& hyperlinks ??)
' This version RETYPED from published Macro because of difficulties with MS Office site.
' CALL with ALT + U (for Underscore)
Dim oRng As Range
Dim oWord As Range
Set oRng = ActiveDocument.Range
With oRng.Find
Do While .Execute(FindText:="_")
Set oWord = oRng.Duplicate
If oWord.Words(1).Start <> ActiveDocument.Range.Start Then
oWord.MoveStartUntil Chr(32), wdBackward
oWord.MoveEndUntil Chr(32) & Chr(13)
If InStr(1, oWord.Text, "@") = 0 Then oRng.Text = " "
End If
oRng.Collapse 0
Loop
End With
MsgBox "Yes, it ran." 'Added.
lbl_Exit:
Set oRng = Nothing
Set oWord = Nothing
Exit Sub
End Sub