Ed Matsuoka
asked on
Random sample of words from a Word document
Hi experts!
I am writing a Word VBA macro to show various Grade Level indexes and one of them requires a random sample of 150 words from a Word doc. What would be the best way to randomly choose those 150 words?
Thanks!
I am writing a Word VBA macro to show various Grade Level indexes and one of them requires a random sample of 150 words from a Word doc. What would be the best way to randomly choose those 150 words?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The x variable isn't needed.
When you say "it didn't work", what do you mean? Did you get an error message?
Did you look in the Immediate Window via Ctrl+g?
Open the attached doc, go to 'ThisDiocument' and run the macro that you'll find there. (You should insert a module and move the code there. And until you add the Randomize line the results will probably always be the same.
29082778.docm
When you say "it didn't work", what do you mean? Did you get an error message?
Did you look in the Immediate Window via Ctrl+g?
Open the attached doc, go to 'ThisDiocument' and run the macro that you'll find there. (You should insert a module and move the code there. And until you add the Randomize line the results will probably always be the same.
29082778.docm
Oh, in that sample I just posted you'll need to change the Const to something less than 150 since there aren't 150 words in the doc.
ASKER
Interesting. When I run it from THIS DOCUMENT it works but when I run the exact same code from a MODULE in my NORMAL.DOT it just churns. Is the reference to THIS DOCUMENT the problem?
Yes, change ThisDocument to ActiveDocument.Content
ASKER
Thanks! I tweaked it as you said and it works. Now I am just going to play around with it since it is slow. Have a great day.
In that case look for samples of code that use a Dictionary object rather than the Collection object.
In any case you’re welcome and I’m glad I was able to help.
If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015, 2017
Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
In any case you’re welcome and I’m glad I was able to help.
If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.
Marty - Microsoft MVP 2009 to 2017
Experts Exchange Most Valuable Expert (MVE) 2015, 2017
Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
ASKER
I tried this and it didn't work. Is some code missing, you DIM x but x isn't used anywhere in the macro.