Try:
Code:
Sub SpaceToUnderscore()
Application.ScreenUpdating = False
Dim StrFnd As String, StrRep As String
With Selection.Range
StrFnd = Trim(.Text)
.Case = wdTitleWord
StrRep = Replace(Trim(.Text), " ", "_")
End With
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = StrFnd
.Replacement.Text = StrRep
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub