![]() |
|
#1
|
|||
|
|||
![]()
Thanks Charles. I am really a beginner so please excuse my ignorance. The doc is a letterhead and the body has the word salutation. When I step into, even though the word salutation is there it skips right to endofsub: without giving "MsgBox strWORDTOFIND & " is present." " . Your kind help is appreciated.
Sub salutation() ' ' ' ' Charles Kenyon ' If word not found skip rest of macro Const strWORDTOFIND As String = "salutation" With ActiveDocument.Range.Find .Text = strWORDTOFIND If .Found = False Then GoTo endofsub End With MsgBox strWORDTOFIND & " is present." Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting With Selection.Find.Font .Bold = False .Italic = False End With Selection.Find.Replacement.ClearFormatting With Selection.Find.Replacement.Font .Bold = False .Italic = False .Underline = wdUnderlineNone End With With Selection.Find .Text = "salutation" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute With Selection If .Find.Forward = True Then .Collapse Direction:=wdCollapseStart Else .Collapse Direction:=wdCollapseEnd End If .Find.Execute Replace:=wdReplaceOne If .Find.Forward = True Then .Collapse Direction:=wdCollapseEnd Else .Collapse Direction:=wdCollapseStart End If .Find.Execute End With Selection.MoveLeft Unit:=wdCharacter, Count:=1 Selection.TypeText Text:= _ "It is a pleasure ...." endofsub: End Sub |
![]() |
Tags |
nubie, search and replace |
|