AW: Formular mit Optionbutton u. Checkbox
09.08.2019 11:58:43
EtoPHG
Hallo Erwin,
Das ganze könnte man etwas kompakter schreiben.
Im Modul Passwort_raus
Public Const c_PWD As String = "007"
Sub Passwort_raus()
ActiveSheet.Unprotect c_PWD
End Sub
Im Klassenmodul der Reservierung Userform
'"Reservierung" starten
Private Sub CommandButton1_Click()
On Error GoTo Errorhandler
Application.EnableEvents = False 'Events ausschalten
Application.Calculation = xlCalculationManual 'keine Berechnungen durchführen
Application.ScreenUpdating = False 'keine Bildschirmaktualisierung
With Worksheets("Tabelle1")
' Schutz ausschalten
.Unprotect c_PWD
' Alles verstecken
.Rows("11:20").Hidden = True
.Rows("21:30").Hidden = True
.Rows("31:40").Hidden = True
' Test OptionButtons
If OptionButton1 Then
.Rows("11:20").Hidden = False
.Cells(4, 2) = Application.UserName
End If
If OptionButton2 Then
.Rows("21:30").Hidden = False
.Cells(6, 2) = Application.UserName
End If
If OptionButton3 Then
.Rows("31:40").Hidden = False
.Cells(8, 2) = Application.UserName
End If
' Test Checkboxen
If CheckBox1 Then .Cells(8, 4) = "checkbox 1 texteintrag"
' Schutz einschalten
.Protect c_PWD, DrawingObjects:=True, Contents:=True, Scenarios:=True
'UF schließen
Me.Hide
End With
'Check for errors
Errorhandler:
With Err
Select Case .Number
Case 0 'alles OK
Case 13 'Inputbox für Zellauswahl wurde abgebrochen
Case Else
MsgBox "Fehler-Nr.: " & .Number & vbLf & .Description
End Select
End With
'Restore Events/Calculation/Screenupdating
Application.EnableEvents = True 'Events einschalten
Application.Calculation = xlCalculationAutomatic 'Berechnungen wieder automatisch
Application.ScreenUpdating = True 'Bildschirmaktualisierung einschalten
End Sub
'"Reservierung" abbrechen
Private Sub CommandButton2_Click() 'Button Abbrechen
Me.Hide 'UF schließen
End Sub
' Beispiel Optionbutton1 soll nur checkbox2 und 3 zulassen
Private Sub OptionButton1_Change()
CheckBox2.Enabled = OptionButton1
CheckBox3.Enabled = OptionButton1
End Sub
' Initialisierung beim userform_Activate
Private Sub UserForm_Activate()
OptionButton1 = False
OptionButton2 = False
OptionButton3 = False
OptionButton4 = False
CheckBox1.Enabled = False
CheckBox2.Enabled = False
CheckBox3.Enabled = False
CheckBox4.Enabled = False
End Sub
Gruess Hansueli