mskralik
asked on
Random number generation in MS Word
Dear Expert,
Is there a random number that can be referenced or activated upon printout or macrobutton activation so that the number can be used as a Reference Bookmark to determine a simple yes/no outcome? If so, how do you write the code?
Is there a random number that can be referenced or activated upon printout or macrobutton activation so that the number can be used as a Reference Bookmark to determine a simple yes/no outcome? If so, how do you write the code?
ASKER
Hi Graham,
Is it possible to just generate a random number as a field updates at the time of printing? I' thinking something like:
{ If {{Rnd} * 1000} > "500" "Yes" "No"}
Thanks
Is it possible to just generate a random number as a field updates at the time of printing? I' thinking something like:
{ If {{Rnd} * 1000} > "500" "Yes" "No"}
Thanks
I'm afraid there isn't a randomising feature in Word fields. You will have to use VBA.
ASKER
Hi Graham,
Thanks for the guidance. Ok, so I try to run the macro as you have it, and the editor pops up with this line of code highlighted -
Set rng = ActiveDocument.Bookmarks(" RandomNumb er").Range
Wnen I place the cursor over the "Set rng" portion of the code, a box pops up that says, "rng = Nothing".
Any ideas?
Thanks
Thanks for the guidance. Ok, so I try to run the macro as you have it, and the editor pops up with this line of code highlighted -
Set rng = ActiveDocument.Bookmarks("
Wnen I place the cursor over the "Set rng" portion of the code, a box pops up that says, "rng = Nothing".
Any ideas?
Thanks
Is there an error message?
ASKER
Yes...sorry that I did not include this earlier.
Run-time error '5941':
The requested member of the collection does not exist.
Run-time error '5941':
The requested member of the collection does not exist.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Sorry,
Is it possible for the code to automatically assign and populate into the bookmark called "RandomNumber"?
Is it possible for the code to automatically assign and populate into the bookmark called "RandomNumber"?
ASKER
Hi Graham,
Thanks for your help, I was able to get this working.
-Michael
Thanks for your help, I was able to get this working.
-Michael
Open in new window