wie kann eine bestimmte Combobox beim aufrufen der Userform aktivieren?
Ich habe 2 ComboBoxen in der Userform und ComboBox1 soll aktiv sein, dh der Cursor in der Box soll blinken!
Im Ablauf der Codes benutze ich "ComboBox1.SetFocus" wenn eine falsche Eingabe gemacht ist.
Ich schon versuch diesen Befehl in verschiedene Positionen zu bringen, aber alles half nichts!
Serge
Hier meine Codes
Private Sub CommandButton2_Click()
If ComboBox1.Value = "" Then
Wahl = MsgBox("Benutzer fehlt?", , Title:=" Benutzer ")
ComboBox1.SetFocus
Else
If ComboBox2 = "" Then
Wahl = MsgBox(" Zweck fehlt?", , Title:=" Zweck ")
ComboBox2.SetFocus
Else
ActiveSheet.Unprotect
Selection.Merge
ActiveCell.FormulaR1C1 = ComboBox1 & Chr(10) & ComboBox2
Selection.RowHeight = 12.75
' ActiveCell.AddComment
' ActiveCell.Comment.Visible = False
' ActiveCell.Comment.Text Text:=ComboBox1 & Chr(10) & ComboBox2 & Chr(10) & Date
Dim cmt As Comment
Dim LOG, UserN$, UserID$
UserID = Environ("Username") ' Der Anmeldename am Netzwerk
UserN = Application.UserName 'der in Excel eingetragenen Name
Set cmt = ActiveCell.AddComment(ComboBox1 & Chr(10) & ComboBox2 & Chr(10) & Chr(10) _
& "Termin erfasst am " & Format(Date, "d.m.yy") _
& Chr(10) & "von " & UserN)
With cmt.Shape.TextFrame.Characters.Font
.Name = "Courier"
.Size = 12
.Bold = False
End With
With cmt.Shape.TextFrame
.AutoSize = True
End With
' With cmt.Shape
' .Height = 90
' .Width = 200
' End With
Unload Me
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
End If
End Sub
Private Sub CommandButton3_Click()
Application.EnableEvents = False
Unload Me
Application.EnableEvents = True
End Sub
Private Sub CommandButton4_Click()
Call Reset
End Sub
Sub Reset()
ComboBox1 = ""
ComboBox2 = ""
End Sub
In eine Modul
Sub commandbutton()
Dim Wahl
ActiveSheet.Unprotect
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Wahl = MsgBox("Wollen Sie im ausgewähltem Bereich " & vbCrLf & vbCrLf & " " & Selection.Address(RowAbsolute:=False, columnAbsolute:=False) & " " & vbCrLf & vbCrLf & " einen Termin festlegen", vbYesNo, "Termin einfügen!")
Application.ScreenUpdating = True
If Wahl = vbYes Then
Selection.Interior.ColorIndex = xlNone
Übersicht.Show
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Else
Selection.Interior.ColorIndex = xlNone
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
End Sub