» » Cara membuat Form Login Pada Excel

Cara membuat Form Login Pada Excel

Penulis By on Kamis, 26 Juni 2014 | No comments

Langsung aja bagaimana cara membuatnya, siapkan 1 Userform, 2 Textbox, 2 Commandbutton.
Lalu masukkan script di bawah ini :


Private Sub cmdKeluar_Click() ThisWorkbook.Close End Sub Private Sub cmdOK_Click() If TextBox1.Value = "" Then MsgBox "Isi Username terlebih dulu", _ vbOKOnly + vbInformation, "User Kosong" TextBox1.SetFocus Exit Sub ElseIf TextBox2.Value = "" Then MsgBox "Isi Password terlebih dulu", _ vbOKOnly + vbInformation, "User Kosong" TextBox2.SetFocus Exit Sub End If Sheets("pas").Select If Range("d1") = False Then LoginSalah = MsgBox("Username atau Password salah" _ & vbCrLf & "Coba masuk lagi?", _ vbYesNo + vbInformation, "Error Masuk") 'Jika tombol Yes yang di-klik If LoginSalah = vbYes Then 'TextBox User dikosongkan TextBox1.Value = "" 'TextBox Password dikosongkan TextBox2.Value = "" 'TextBox User menjadi fokus TextBox1.SetFocus ElseIf LoginSalah = vbNo Then Unload Me End If 'Jika user dan password yang dimasukkan benar Else 'Keluar dari Form Login Unload Me 'Menampilkan kotak pesan login berhasil MsgBox "User dan Password benar", _ vbOKOnly + vbInformation, "Login Berhasil" End If End Sub Private Sub TextBox1_Change() Sheets("pas").Select Range("b1") = TextBox1 End Sub Private Sub TextBox2_Change() Sheets("pas").Select Range("b2") = TextBox2 End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode <> 1 Then Cancel = True End Sub


Baca Juga Artikel Terkait Lainnya