Tworze formularz w VBA który ma za zadanie wysłanie danych do zakładki która jest ukryta i chroniona hasłem. Z jekiegos powodu mój kod działa tylko wtedy kiedy zakładka jest wywołana mimo że w kodzie nie ma komendy active sheet. Czy ktoś może pomóc? Dopiero raczkuje z VBA więc prosze nie zlinczujcie mnie. Pozdrawiam
Pierwszy raz słyszę narzekanie, że kod działa :)
A tak serio, to pokaż go, to ci wyjaśnię, czemu działa i kiedy by nie działał.
userform1
Private Sub UserForm_activate()
With Me.ComboBox1
.Clear
.AddItem "Policy"
.AddItem "Leavers"
.AddItem "Digital ways of working"
.AddItem "Death in service"
.AddItem "New start contracts"
.AddItem "Induction Information"
.AddItem "Maternity Leave Calculator"
.AddItem "Anual leave calculator"
End With
End Sub
Private Sub CommandButton10_Click() '''add
erow = Sheets("MASTER").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1) = TextBox1.Text
Cells(erow, 2) = TextBox2.Text
Cells(erow, 3) = TextBox3.Text
Cells(erow, 4) = TextBox4.Text
Cells(erow, 5) = DTPicker1.Value
Cells(erow, 6) = ComboBox1.Value
Cells(erow, 7) = TextBox5.Text
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
ComboBox1.Value = ""
End Sub
**
userform password**
Private Sub enterPassword()
Dim password As String
password = "test"
If TextBox1.Value = password Then
Call Module4.hide_worksheet(False)
MsgBox "worksheet visible", vbInformation, "success"
Else
MsgBox "Incorrect Password", vbCritical, "Error"
End If
End Sub
Private Sub CommandButton1_Click()
Call enterPassword
End Sub
Private Sub TextBox1_keyDown(ByVal KeyCode As MsForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
Call enterPassword
End If
End Sub
Private Sub UserForm_Click()
End Sub
**module verry hidden **
Sub openUserform1()
UserForm1.Show
UserForm1.TextBox1.SetFocus
End Sub
Sub hide_worksheet(x As Boolean)
If x = True Then
Sheets("MASTER").Visible = xlVeryHidden
Else
Sheets("MASTER").Visible = True
End If
End Sub
Sub test()
Call hide_worksheet(True)
End Sub