Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 22,512
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
 



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 05:03 AM.


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