Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-02-2012, 07:35 PM
macropod's Avatar
macropod macropod is offline Find and Prompt the user to Replace Windows 7 64bit Find and Prompt the user to Replace Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default


Try:
Code:
Sub PromptReplace()
Dim Rng As Range, i As Long
Dim strFnd As String, strRpl As String
Dim fnd As String, rpl As String, choice As Integer
'find string
strFnd = "tot;tow;trail;contact;delivery;fist;form;latter;diffused;singed;sing;asset;tortuous;emotion;owning;statue;conversion"
'replace string in same order as strFnd
strRpl = "to;two;trial;contract;deliver;first;from;later;defused;signed;sign;assert;tortious;motion;owing;statute;conversation"
For i = 0 To UBound(Split(strFnd, ";"))
  fnd = Split(strFnd, ";")(i)
  rpl = Split(strRpl, ";")(i)
  For Each Rng In ActiveDocument.StoryRanges
    With Rng
      With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = fnd
        .Forward = True
        .Wrap = wdFindStop
        .Execute
      End With
      While .Find.Found
        .Duplicate.Select
        choice = MsgBox("Replace " & Chr(34) & fnd & Chr(34) & " with " & Chr(34) & rpl & Chr(34) & "?", _
                vbYesNoCancel + vbDefaultButton1, "Replace")
        If choice = vbYes Then
          .Text = rpl
        ElseIf choice = vbCancel Then
          GoTo endit
        End If
        .Collapse wdCollapseEnd
        .Find.Execute
      Wend
    End With
  Next Rng
Next i
endit:
Set Rng = Nothing
End Sub
Do be aware that the message box is liable to obscure the found text.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 11-04-2012, 08:27 AM
Lawmuse Lawmuse is offline Find and Prompt the user to Replace Windows 7 32bit Find and Prompt the user to Replace Office 2010 32bit
Novice
Find and Prompt the user to Replace
 
Join Date: Nov 2012
Posts: 4
Lawmuse is on a distinguished road
Default

Thank you. That seems to work perfectly. You revisions are very subtle, but it appears that the main difference is
Code:
.Duplicate.Select
Which I never would have discovered. So this creates a duplicate of the current range object, the current find, and selects it which highlights it on the screen behind the msgbox. Is there anything else I'm missing about this and how did you come up with it.

The other changes look like simple clean up stuff, though is moving the for each range... inside the for loop necessary... Never mind, I see now that it is. We need to set the ranges for each of the search pairs.
Reply With Quote
Reply

Tags
code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Prompt the user to Replace Find, Replace Ajay Shahane Word VBA 4 05-16-2012 04:07 AM
Find and Prompt the user to Replace Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
Find and Prompt the user to Replace Is there a way to use "find/replace" to find italics words? slayda Word 3 09-14-2011 02:16 PM
Find and Prompt the user to Replace Help with find and replace or query and replace shabbaranks Excel 4 03-19-2011 08:38 AM
User Name Prompt Appears When Opening Documents galleherjazz Office 0 07-30-2009 08:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:34 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft