Trevor3007
Well-known Member
- Joined
- Jan 26, 2017
- Messages
- 675
- Office Version
- 365
- Platform
- Windows
good evening,
I use the following:-
Sub Gencode()
Static IsRandomized As Boolean
Dim i As Integer, PW1 As String
Dim cell As Range, PW As String
With Sheets("code") ' Change Code to the name of the sheet this is to work on.
.Unprotect
If Not IsRandomized Then Randomize: IsRandomized = True
For Each cell In .Range("b3:b200")
PW = vbNullString
For i = 1 To 8
Do
DoEvents
PW1 = Chr(Int((97 - 122 + 1) * Rnd + 122)) ' Lower case alpha
Loop Until InStr(1, PW, PW1, 1) = 0
PW = PW & PW1
Next i
PW = Replace(PW, Mid(PW, Int(8 * Rnd + 1), 1), Int(8 * Rnd + 1))
cell.Value = PW
Next cell
.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowFormattingCells:=True
End With
End Sub
I am trying to insert a 'Yes/No' message box
Message "This Will Reset Your Previous Generated Codes, Do You Want To Save The File 1st Then Generate New Codes Or Just Generate New Codes?"
If Yes, then save the file a selected location (rather than just IE c:\myfiles) and then generate new codes.
if no, just generate new codes
Having tried to do the above myself but my attempts has just caused a boat load of errors especially with wanting to save to a random location.
Hoping someone can help.
KR
Trevor3007
I use the following:-
Sub Gencode()
Static IsRandomized As Boolean
Dim i As Integer, PW1 As String
Dim cell As Range, PW As String
With Sheets("code") ' Change Code to the name of the sheet this is to work on.
.Unprotect
If Not IsRandomized Then Randomize: IsRandomized = True
For Each cell In .Range("b3:b200")
PW = vbNullString
For i = 1 To 8
Do
DoEvents
PW1 = Chr(Int((97 - 122 + 1) * Rnd + 122)) ' Lower case alpha
Loop Until InStr(1, PW, PW1, 1) = 0
PW = PW & PW1
Next i
PW = Replace(PW, Mid(PW, Int(8 * Rnd + 1), 1), Int(8 * Rnd + 1))
cell.Value = PW
Next cell
.Protect DrawingObjects:=False, Contents:=True, Scenarios:=False, AllowFormattingCells:=True
End With
End Sub
I am trying to insert a 'Yes/No' message box
Message "This Will Reset Your Previous Generated Codes, Do You Want To Save The File 1st Then Generate New Codes Or Just Generate New Codes?"
If Yes, then save the file a selected location (rather than just IE c:\myfiles) and then generate new codes.
if no, just generate new codes
Having tried to do the above myself but my attempts has just caused a boat load of errors especially with wanting to save to a random location.
Hoping someone can help.
KR
Trevor3007
Last edited: