View Single Post
 
Old 07-30-2012, 10:11 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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