Word VBA Macro Find Text

S

spovolny

I KNOW Microsoft Word has a find function - but I'm looking for a way
to find all occurrences of a string in a document. I set up a text
box to enter the string (for example "abcd") and a button to "Find
Now". It will find the first occurrence, but I would like to know how
to get the number of all occurrences of "abcd" throughout the
document. Sorry this is a newbie question - I don't know VBA too well
yet. Thanks in advance to anyone who can help.
Steve
 
G

Greg Maxey

You don't need a macro for this. Instead of using Find use Replace.
Find "abcd" and replace with "abcd" click "Replace All." Word will
tell you how many times it performs the replacement.
 
S

spovolny

You don't need a macro for this. Instead of using Find use Replace.
Find "abcd" and replace with "abcd" click "Replace All." Word will
tell you how many times it performs the replacement.

Thanks -
I do know how to do this and get the number of replacements - is there
a way to store this number in a variable? When I ran it as a recorded
macro, it doesn't record the number of replacements made which is the
number I'm looking for. Any ideas?
 

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