Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. Sub ReplaceAndFormat16()
  2. Dim sConst1 As String, sReplaceMent As String
  3. Dim rRange As Range, rFormat As Range
  4. sConst1 = "Fish"
  5. sReplaceMent = "Oil (" & sConst1 & ")"
  6. Selection.Find.ClearFormatting
  7. Selection.Find.Replacement.ClearFormatting
  8. With Selection.Find
  9. .Text = "Oil (Fish)"
  10. .Replacement.Text = sReplaceMent
  11. .Forward = True
  12. .Wrap = wdFindContinue
  13. .Format = False
  14. .MatchCase = True
  15. .MatchWholeWord = False
  16. .MatchWildcards = False
  17. .MatchSoundsLike = False
  18. .MatchAllWordForms = False
  19. .Execute Replace:=wdReplaceOne
  20. If .Found Then
  21. Set rRange = Selection.Range
  22. Set rFormat = ActiveDocument.Range(rRange.Start + 5, rRange.Start + 5 + VBA.Len(sConst1))
  23. rFormat.Font.Bold = True
  24. End If
  25. End With
  26. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement