Sub reallyrando()
'https://www.mrexcel.com/board/threads/using-activex-commandbutton-to-create-random-password.1208398/
'by portews
Dim randtime as integer, randchar as integer
Dim i as integer, newchar, x
dim newPW as string
'get a random amount of characters between 6 and 12 long
randtime = GetRando(6, 12)
'for each of those characters...
For i = 1 To randtime
'get a random character based on the ASCII table for easily typed characters
newchr = GetRando(33, 126)
'if something went wrong, quit
If newchr = "Invalid" Then x = MsgBox("Invalid Parameters", vbOKOnly, "New Password"): End
'concatenate the string with the new character
newPW = newPW & Chr(newchr)
'erase your temporary character and do it again
newchr = ""
Next
'print out your new password in an input box so you can copy it easily
x = MsgBox("New " & randtime & " character password" & vbCrLf & newPW, vbOKOnly, "New Password")
End Sub
Function GetRando(lower As Integer, upper As Integer)
Randomize CDbl(Now())
If lower < upper Then
GetRando = Int((upper - lower + 1) * Rnd + lower)
Else
GetRando = "Invalid"
End If
End Function