Random password gen - Excel VBA
To attach a button to the macro, go to the view menu, select toolbars, then select Control Toolbox. Select the icon that looks like a button (if you hover over it it will say "Button"). Draw the button where ever you want it on the sheet. If the macro is already in VBA, a dialog box will open asking you which macro you want to attach the button to. Select the appropriate one and you should be good to go.
If the macro is not in VBA when you create the Button, then once you have added the macro, right click on the button and select "Assign Macro..."
Below is the full corrected form of the macro i posted earlier. If you don't want to generate multiple passwords with one click of the button, replace everything after the "Next k" line with
MsgBox "The password is " & Password & "."
Sub RandomPassword()
Dim i As Integer, j As Integer, k As Integer
Dim Password As String
Begin:
Password = ""
For k = 1 To 2
Randomize
i = Int(10 * Rnd + 1)
Randomize
j = Int(10 * Rnd + 1)
Password = Password & Worksheets("sheet1").Cells(3 + i, 2 + j)
Next k
Dim answer As Integer
answer = MsgBox(Prompt:="Password is " & Password & _
". Do you want to generate another?", Buttons:=vbYesNo)
If answer = vbYes Then GoTo Begin
End Sub
|