Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-26-2012, 04:49 PM
ahrinn ahrinn is offline Random number difficulties Windows XP Random number difficulties Office 2007
Novice
Random number difficulties
 
Join Date: Jul 2012
Posts: 7
ahrinn is on a distinguished road
Default Random number difficulties

Hello,
This is a rather lengthy problem, so please bear with me. I am working on creating a document with two random number fields. I have used excel's "RAND" command to create the random number itself ( 6 digit integers from 000000 to 999999 ) and have inserted the cell as an object to my word document. I have two fields needing this number ( one on each page ). My problem is that I need the number to be the same in each field. If I insert the object onto both pages, I get two separate numbers. I tried copying the cell and pasting it to my document as a link to the original excel workbook. This helps to a point, so long as I have both files open at the same time. Then I can recalculate in Excel, print in word, and repeat the process several times. If I close either document, though, I fail to get a new number, or the numbers don't match in the two fields. Ideally, I'd like to end up with a two page document that I can set to print a couple hundred copies with a different number on each copy, but the same number on each two page set. For example page one has "123456" and page two has "123456," then the next print of page one would have "321465" and page two would have the same "321465". I hope to end up with several unique two page sets, so that upon distribution, I can give page one to my clerk and page two to my client and they each have the same number at the bottom. The next set would have a different number for the new client. I'm not even sure if this is possible in office or how to accomplish it if it is. Any help would be greatly appreciated, and I hope that this made sense.
Reply With Quote
  #2  
Old 07-26-2012, 11:40 PM
macropod's Avatar
macropod macropod is offline Random number difficulties Windows 7 64bit Random number difficulties Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

hi ahrinn,

See if the attached does what you want. Basically, the document has a formfield that calls a macro to put a number in it. A cross-reference field then replicates the number at another location. No Excel involvement.
Attached Files
File Type: doc Random.doc (43.0 KB, 12 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-27-2012, 09:41 AM
ahrinn ahrinn is offline Random number difficulties Windows XP Random number difficulties Office 2007
Novice
Random number difficulties
 
Join Date: Jul 2012
Posts: 7
ahrinn is on a distinguished road
Default

Hi Paul,
That looks like it may work, but how would I set the macro up in my document? Also, does it generate a different number each time it's opened? I'd love to be able to print a couple hundred copies with a different number on each copy, but I wasn't sure if that would work. Sorry for all the questions, my office experience and needs aren't usually this in depth.

Thanks a lot.
Reply With Quote
  #4  
Old 07-27-2012, 03:34 PM
macropod's Avatar
macropod macropod is offline Random number difficulties Windows 7 64bit Random number difficulties Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

hi ahrinn,

Do you want the number to update automatically when you open the document, or only when you decide? Do note that, whichever way you go, there is a small risk that the generated number will be the same as one you've used before. At present it does the latter - simply pressing the tab key updates it. The macro is quite simple, but it needs to be coded differently - and perhaps the document designed differently, according to what you want.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-28-2012, 04:15 AM
ahrinn ahrinn is offline Random number difficulties Windows XP Random number difficulties Office 2007
Novice
Random number difficulties
 
Join Date: Jul 2012
Posts: 7
ahrinn is on a distinguished road
Default

Could we try each way and see which ends up working better? Only if that's not too much trouble. Thanks again for all your help.


Quote:
Originally Posted by macropod View Post
hi ahrinn,

Do you want the number to update automatically when you open the document, or only when you decide? Do note that, whichever way you go, there is a small risk that the generated number will be the same as one you've used before. At present it does the latter - simply pressing the tab key updates it. The macro is quite simple, but it needs to be coded differently - and perhaps the document designed differently, according to what you want.
Reply With Quote
  #6  
Old 07-28-2012, 06:13 PM
macropod's Avatar
macropod macropod is offline Random number difficulties Windows 7 64bit Random number difficulties Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi ahrinn,

See attached. On opening the document, you'll get a prompt to allow macros to run. If you do so, you'll then get asked whether to update the random number. If you answer Yes, it'll be updated. To update the number afterwards, press Alt-F8, then click on 'UpdateRandomNumber', OK.

If that's what you want, I'll explain how to implement it.
Attached Files
File Type: doc Random.doc (32.5 KB, 15 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 07-30-2012, 06:45 AM
ahrinn ahrinn is offline Random number difficulties Windows XP Random number difficulties Office 2007
Novice
Random number difficulties
 
Join Date: Jul 2012
Posts: 7
ahrinn is on a distinguished road
Default

That looks just about right. Could it be made to update on opening without asking permission? Otherwise, it looks just about perfect. Thanks again for all your help.

Quote:
Originally Posted by macropod View Post
Hi ahrinn,

See attached. On opening the document, you'll get a prompt to allow macros to run. If you do so, you'll then get asked whether to update the random number. If you answer Yes, it'll be updated. To update the number afterwards, press Alt-F8, then click on 'UpdateRandomNumber', OK.

If that's what you want, I'll explain how to implement it.
Reply With Quote
  #8  
Old 07-30-2012, 06:57 AM
ahrinn ahrinn is offline Random number difficulties Windows XP Random number difficulties Office 2007
Novice
Random number difficulties
 
Join Date: Jul 2012
Posts: 7
ahrinn is on a distinguished road
Default

I do notice that it seems to pull numbers from a set list. Every time I open it and agree to update the number, I get the same number. If I tell it to update when already open, it seems to come up with the same numbers in the same order. Is there a way to get around this? Out of curiosity, if I told it to print 100 copies of the document, would there be a way to get a different number on each document, or would it print 100 copies with exactly the same number? If I'm asking for the impossible, please let me know. Thanks again for all your help and knowledge.
Reply With Quote
  #9  
Old 07-30-2012, 10:11 PM
macropod's Avatar
macropod macropod is offline Random number difficulties Windows 7 64bit Random number difficulties Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi ahrinn, to create a document with fully-random numbers being generated automatically upon opening:
• create the document;
• press Alt-F11 to open the vba environment;
• on the left you'll see your document's name. Expand that and you'll see a 'ThisDocument' entry. Double-click on that.
• in the 'ThisDocument' module, insert the following code -
Code:
Private Sub Document_Open()
Call UpdateRandomNumber
End Sub
 
Sub UpdateRandomNumber()
Randomize Timer
With ActiveDocument
  .CustomDocumentProperties("RandNum").Value = Format(Int(1000000 * Rnd), "000000")
  .Fields.Update
End With
End Sub
• press Alt-F11 to return to the document
• add a numeric custom document property named 'RandNum' to your document, with a value of 0. To do this, use the Pizza Button, then choose Properties|Advanced|Custom.
• wherever you want the random numbers to appear, insert a DOCPPROPERTY field coded as {DOCPPROPERTY RandNum}, where the field braces (ie '{}') are created via Ctrl-F9.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #10  
Old 07-31-2012, 12:18 AM
macropod's Avatar
macropod macropod is offline Random number difficulties Windows 7 64bit Random number difficulties Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: http://answers.microsoft.com/en-us/o...3-e33b61363140
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

It is extremely poor form to post a question relating to a topic you've already been given considerable help for without aknowledging or referencing the help you've already received.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 07-31-2012, 04:24 AM
ahrinn ahrinn is offline Random number difficulties Windows XP Random number difficulties Office 2007
Novice
Random number difficulties
 
Join Date: Jul 2012
Posts: 7
ahrinn is on a distinguished road
Default

I apologize if I have offended you. I do appreciate all your help.


Quote:
Originally Posted by macropod View Post
Cross-posted at: http://answers.microsoft.com/en-us/o...3-e33b61363140
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

It is extremely poor form to post a question relating to a topic you've already been given considerable help for without aknowledging or referencing the help you've already received.
Reply With Quote
  #12  
Old 07-31-2012, 05:52 AM
macropod's Avatar
macropod macropod is offline Random number difficulties Windows 7 64bit Random number difficulties Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It's really not an issue of offending someone, but of wasting peoples' time. Those who make a habit of cross-posting without either providing links or acknowledging the fact they've already received help on an issue very soon find no-one willing to help them. I have also known a number of people to be banned from some forums for repeatedly breaching this basic convention.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 08-01-2012, 01:04 PM
ahrinn ahrinn is offline Random number difficulties Windows XP Random number difficulties Office 2007
Novice
Random number difficulties
 
Join Date: Jul 2012
Posts: 7
ahrinn is on a distinguished road
Default

Okay, document is created and successful. Thanks again for your help and instruction.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
random pop up wont go away 464646 OneNote 0 05-01-2012 04:34 AM
how can i make random variant neezeen Word 0 11-22-2011 08:08 AM
Random number generator for Powerpoint 2011 kala85 PowerPoint 0 11-19-2011 06:16 AM
Random number difficulties Visio random crash? maxoys45 Visio 5 10-25-2010 09:15 AM
Random number difficulties Random names from a given list professor snape Excel 1 06-06-2009 09:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft