Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Find/Replace Total Count

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AviBu - 21 Nov 2004 04:27 GMT
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?
Helmut Weber - 21 Nov 2004 13:10 GMT
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/
Greg Maxey - 21 Nov 2004 14:36 GMT
Have a look at:

http://gregmaxey.mvps.org/Find_it_tool_bar.htm
It doesn't use replace all, but does provide a count of words found.

Signature

Greg Maxey/Word MVP
A Peer in Peer to Peer Support

> 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?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.