Find/Replace Total Count

A

AviBu

How can I get VBA to tell me how many search-and-replaces were made when
using the wdReplaceAll option in the Selection.Find.Execute method? When
doing a "Replace All" from the Find dialog in Word, it tells me the total. Is
there a way to retrieve this info programmatically?
 
H

Helmut Weber

Hi,
just for fun, and I'd rather accept some seconds of waiting
and use range.find while execute i = i + 1 etc., but
it is sometimes very strange, what quirk workaraounds could do,
like this one:
Sub Test115()
Dim i As Long
Dim strMsg As String ' the error message
Dim strCnt As String ' replace counter
Dim dlgtest As Dialog
Set dlgtest = Dialogs(wdDialogEditReplace)
Selection.HomeKey unit:=wdStory
On Error GoTo Message ' no reason for an error, but still ...
dlgtest.Find = "e" ' search for "e"
dlgtest.Replace = "e" ' replace with "e"
SendKeys "%a"
SendKeys "{tab 3}"
SendKeys "{ENTER}"
dlgtest.Display ' executes ! I wonder!
Message:
strMsg = Err.Description
' isolate the number from the err.description, that's easy
For i = 1 To Len(strMsg)
If IsNumeric(Mid(strMsg, i, 1)) Then
strCnt = strCnt & Mid(strMsg, i, 1)
End If
Next i
MsgBox strCnt
End Sub
---
I wonder, where the error.description comes from,
as there seems not to be any error.
And, further more, "dlgtest.display" shouldn't execute
the search and replace. But it obviously does.
Must have been a disastrous or vice versa very funny day at MS,
when this was coded.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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