![]() |
#3
|
|||
|
|||
![]()
Found this while surfing and uses it to replace words(s). The problem is if the word searched by macro is correct, it still corrected the word plus moving the last letter.
Example: From "Replace" will be added "d" and changed it to "Replaced". Some are corrected but some that searched as "Replaced" will changed to "Replacedd" (adding another d). How can I fix this? Code:
Sub Replaced() Dim myStoryRange As Range 'First search the main document using the Selection With Selection.Find .Text = "Replace" .Replacement.Text = "Replaced" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With 'Now search all other stories using Ranges For Each myStoryRange In ActiveDocument.StoryRanges If myStoryRange.StoryType <> wdMainTextStory Then With myStoryRange.Find .Text = "Replace" .Replacement.Text = "Replaced" .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Do While Not (myStoryRange.NextStoryRange Is Nothing) Set myStoryRange = myStoryRange.NextStoryRange With myStoryRange.Find .Text = "De" .Replacement.Text = "Replaced" .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Loop End If Next myStoryRange End Sub Last edited by macropod; 03-19-2013 at 03:07 PM. Reason: Added code tags & formatting |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
search on multiple word documents | Guy Roth | Word | 7 | 03-06-2017 01:31 PM |
![]() |
gbrucken | Word | 1 | 04-30-2012 10:40 AM |
![]() |
antaeusguy | Word | 1 | 03-14-2012 04:01 AM |
![]() |
anano | Word | 1 | 01-11-2012 09:03 AM |
Search Problems in MS Word | LoganB | Word | 0 | 09-03-2010 06:49 AM |