F
F
Fireman412015-10-06 11:43:11
Visual Basic
Fireman41, 2015-10-06 11:43:11

VBA: Random number every time you open an excel workbook?

Good afternoon!
A book has been created in which a macro generates a random number every time it is opened, delays the execution of the macro body for a random number of seconds. Macro placed in "ThisBook" section
Private Sub Workbook_Open()
random_number = Int(50 * Rnd) + 1
MsgBox random_number
Application.Wait Time:=Now + TimeValue("00:00:" & random_number)
MsgBox random_number
End Sub
The problem is that each time you open the book, the same number is generated.
How can this be fixed?
It is necessary that the macro opens exactly when this workbook is opened.
Thanks for the help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
John Smith, 2015-10-06
@Fireman41

Try to change the seed using Randomize, as indicated by the link .
There is also a sample code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question