Timers with macros

D

Designingsally

Hi I got this huge doc(say abt 50 pages) I have this simple find and replace
macros to work on this doc. The macros are cool enough and working great. But
there are an issue that is highly bothering me.

When I have this huge doc (50 pages) i want to literally to see the change
happening in the document.what i mean is that i can see the change and within
a fraction of a second the macros are moving into the nextplace for finding.
The process is way to fast. cos sometimes the word might fit into the
context, while at some other time it does. So I want some kinda timer to be
set so as to see that word is being replaced and me having the time to read
and realise that it fits into the context or not.
I ll be glad if someone comes with a proper solution. I have no clue if this
can be achieved or not. If this cant be achieved pls suggest some other
alternative.

I ll paste a sample macro code below.


Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "etc" 'the word to find
sRepText = "and so on" 'the word to replace
With Selection
..HomeKey wdStory
With .FInd
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = True
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
 
P

Pesach Shelnitz

Hi Sally,

I modified your macro so that it makes each change, highlights it, and asks
the user to confirm each change. If the user clicks No or Cancel, the
original text is restored. Try it and see if it does more of what you want.

Sub ConfirmReplacement()
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "etc" 'the word to find
sRepText = "and so on" 'the word to replace
With Selection
..HomeKey wdStory
With .Find
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = True
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
orng.Text = sRepText
orng.Select
sRep = MsgBox("Confirm the replacement of '" _
& sFindText & "' by the highlighted text", _
vbYesNoCancel)
If sRep = vbCancel Then
Selection.Text = sFindText
Exit Sub
End If
If sRep = vbNo Then
Selection.Text = sFindText
Else
Selection.Collapse wdCollapseEnd
End If
Wend
End With
End With
End Sub
 
D

Designingsally

Hi Pesach

Thanks for the reply. macros works good. But when i press No it must change
to etc right whcih the macros are doing. But i actually cant see the change
their. the macros is immediately chks for next word instance and displays the
message box there. i want some time to read the sentence. is that possible
probably if u can open a huge doc and chk u can ll understand what i mean to
say.

Btw i have no clue if what i say is practical or not. Kindly direct me
 
D

Designingsally

what i mean to say is . The process so very fast that i m actually not able
to see the change. If i click yes or no, everything is happening in a
fraction of a second. Is it possible to set some timer to slow down so that
user can see that change HAS happened?

thanks in advance.
 
P

Pesach Shelnitz

Hi Sally,

You can have a message box appear after the text is restored by adding the
following line immediately before the line consisting of the one word Else.

MsgBox "The original text has been restored."
 
D

Designingsally

can you show me with a simple example so that i can understan better.


thanks in advance

sally
 
D

Designingsally

thanks for the reply. let me explain to you so that you can understand
better. Probably you can also advise if this is feasible or not.

consider a simple program and data given below. And now copy this word fine
for abt a page. Just that word alone. Now run the macro. THe macro ll run
good. you can see that the change happens extremely fast and the it jumps to
next word. when the words are in same doc then i can see the change. what if
the words are scattered across a big document. and words scatters across
pages. Macros ll jump across pages at one shot. in that case the user
actually cant see the change happenng ( though it is happening) is it
possible to cause a delay of 5 secs or so before the macros jump into next
word in teh line?

pls tell me how to go abt it. I m not sure if this is possible. try with
this macro given below


Sub check()
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "fine" 'the word to find
sRepText = "finD" 'the word to replace
With Selection
..HomeKey wdStory
With .Find
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = True
..MatchWholeWord = True
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace with finD?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
sFindText = "many" 'the word to find
sRepText = "ues" 'the word to replace
With Selection
..HomeKey wdStory
With .Find
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace with uses?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
End With
End With
End With
End With
End Sub

I believe in Hope.

DesigningSally
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top