1. Home
  2. Computing & Technology
  3. Visual Basic

VBA - The Word Working Partner - Part 3

By Dan Mabbutt, About.com

4 of 7

Automate Find and Replace Example - Page 2

~~~~~~~~~~~~~~~~~~~~~~~~~
With Selection.Find
  .Text = "aaa" ' text to be found
  .Replacement.Text = "xxx" ' replacement text
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = True
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
  .Text = "bbb" ' text to be found
  .Replacement.Text = "yyy" ' replacement text
  .Forward = True
  .Wrap = wdFindContinue
  .Format = False
  .MatchCase = True
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

... <and many, many more just like this> ...
~~~~~~~~~~~~~~~~~~~~~~~~~

4 of 7

Explore Visual Basic

More from About.com

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB 6
  5. Learn VBA
  6. VBA - The Word Working Partner - Part 3

©2008 About.com, a part of The New York Times Company.

All rights reserved.