Iamlaosong
A very simple function, there are many online generators, there are also gadgets can be downloaded, here with VBA to do one, the results are saved to the current worksheet, simple, fast. The build function can also be used in other programs. The process of implementing a function is to use a variable to hold all the characters used, and then to take different substrings according to the level, and then to generate random numbers, and remove the characters from the substring to match the random password. The procedure is as follows:
' Generate password and save to current sheet sub GetPassword () len1 = Cells (2, 3) LEV1 = Cells (2, 4) NUM1 = Cells (2, 5) MaxRow = actives Heet. UsedRange.Rows.Count If maxrow >= 2 then Range ("a2:a" & MaxRow). ClearContents End If for row1 = 2 to NUM1 + 1 Cells (row1, 1) = GENPASSWD (Len1, LEV1) Next row1 End Su B ' generate random cipher function, Level 1 = number, Level 2 = number + lowercase letter, Level 3 = number + case letter, Level 4 = number + case Letter + symbol function genpasswd (length, levels) Dim allstr, substr, passwd as String allstr = "[Email protected]#$%^&* ()" Select Case level Case 1 strlen = Case 2 strlen = 3 strlen = + Case Else strlen = substr End Select = left (al Lstr, strlen) ' Debug.Print substr passwd = "" For i = 1 to length passwd = passwd & Mid (substr, in T (Rnd * strlen + 1), 1) Next genpasswd = Passwdend Function
This program: Click to open the link
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"VBA Study" generates random passwords