SOLVED

Can I count the number of replaced texts in VBA

%3CLINGO-SUB%20id%3D%22lingo-sub-2119808%22%20slang%3D%22en-US%22%3ECan%20I%20count%20the%20number%20of%20replaced%20texts%20in%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2119808%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20am%20changing%20all%20instances%20of%20text1%20to%20text2%20in%20my%20document%20in%20VBA.%3C%2FP%3E%3CP%3EThe%20change%20itself%20is%20very%20easy%3C%2FP%3E%3CP%3ESet%20WordRange%20%3D%20ActiveDocument.Content%3C%2FP%3E%3CP%3EWordRange.Find.Execute%20FindText%3A%3D%22Text1%22%2C%20ReplaceWith%3A%3D%22Text2%22%2C%20Replace%3A%3DwdReplaceAll%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20I%20want%20to%20know%20how%20many%20replacements%20were%20made.%3C%2FP%3E%3CP%3EIs%20there%20any%20way%20of%20finding%20this%20out%3F%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2120038%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20I%20count%20the%20number%20of%20replaced%20texts%20in%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2120038%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F501319%22%20target%3D%22_blank%22%3E%40Stefan_Blom%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you.%3C%2FP%3E%3CP%3EAn%20interesting%20way%20of%20doing%20it.%3C%2FP%3E%3CP%3EI%20will%20have%20a%20play%20with%20this%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2119988%22%20slang%3D%22en-US%22%3ERe%3A%20Can%20I%20count%20the%20number%20of%20replaced%20texts%20in%20VBA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2119988%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F920454%22%20target%3D%22_blank%22%3E%40Gilgamesh1964%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESee%20%3CA%20href%3D%22https%3A%2F%2Fwordmvp.com%2FFAQs%2FMacrosVBA%2FGetNoOfReplacements.htm%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwordmvp.com%2FFAQs%2FMacrosVBA%2FGetNoOfReplacements.htm%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi,

I am changing all instances of text1 to text2 in my document in VBA.

The change itself is very easy

Set WordRange = ActiveDocument.Content

WordRange.Find.Execute FindText:="Text1", ReplaceWith:="Text2", Replace:=wdReplaceAll

 

But I want to know how many replacements were made.

Is there any way of finding this out?

Thanks

2 Replies
best response confirmed by Gilgamesh1964 (Occasional Contributor)

@Stefan_Blom 

Thank you.

An interesting way of doing it.

I will have a play with this