Print Page | Close Window

replace word one by one

Printed From: www.exp-systems.com
Category: PDF reDirect
Forum Name: Programming
Forum Discription: VBA and Batch Tools to control PDF reDirect Pro
URL: http://www.exp-systems.com/Forum_exp/forum_posts.asp?TID=628
Printed Date: 29 Apr 24 at 6:25PM


Topic: replace word one by one
Posted By: hiaim
Subject: replace word one by one
Date Posted: 15 Aug 10 at 5:52PM
Hi,

if a word repeated several times in a word document following macro should ask to change before every occurrence/word. suppose word "facet" has to replace with "subject area" and "facet" is repeated 3 times in a document. it should ask to change at every word. i tried wdReplaceOne as well but it is not working ... any solution , any other way to achieve this ???

Dim a As Integer, myRange As Range
    mySearch = InputBox("Enter string to search for:", "Searchstring", "")
    myReplace = InputBox("Enter string to replace " & mySearch & " with:", "Replacestring", "")
    
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
            .Text = mySearch
            .Replacement.Text = myReplace
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchByte = False
            .CorrectHangulEndings = True
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = False
            .MatchFuzzy = False
    End With
' Selection.Find.Execute
    Do While Selection.Find.Found = True
    
   ' If Selection.Find.Found = True Then
        a = MsgBox("Do you want to change?", vbYesNo, "Confirmation")
       
        If a = 6 Then
            Selection.Find.Execute Replace:=wdReplaceOne
            Selection.EndKey Unit:=wdStory
        End If
        Selection.Find.Execute
    'End If
    Loop



Replies:
Posted By: Michel_K17
Date Posted: 15 Aug 10 at 10:32PM
Hi,

   You might have more luck posting in a forum that specifically caters to Word VBA coding. This forum is for PDF reDirect users, so you it is unlikely you will get an answer here.

   Cheers!


-------------
Michel Korwin-Szymanowski
EXP Systems LLC



Print Page | Close Window