Private Sub CommandButton1_Click() Dim mekey As String Dim lchr As Integer mekey = "" Cells(1, 1) = ""
mekey = InputBox("請輸入亂數密碼長度:", vbOKCancel, 6) lchr = Val(mekey) If lchr <= 0 Then MsgBox "不可以為0" Else Randomize For i = 1 To lchr Cells(1, 1) = Cells(1, 1) & Chr(Int((126 - 33 + 1) * Rnd() + 33)) Next i End If End Sub