0
我有下面的代码来设置用户形式中的文本框“txtA”的时间格式。excel用户形式的文本框的时间格式
Private Sub txtA_Afterupdate()
Dim tString As String
With txtA
'Check if user put in a colon or not
If InStr(1, .Value, ":", vbTextCompare) = 0 And Len(.Value) > 1 Then
'If not, make string 4 digits and insert colon
tString = Format(.Value, "0000")
tString = Left(tString, 2) & ":" & Right(tString, 2)
txtA.Value = Format(TimeValue(tString), "hh:mm")
Else
'Otherwise, take value as given
.Value = Format(.Value, "hh:mm")
End If
End With
假设我说20个文本框,(A - E)使一个组(F-H)使另一个组,等等。现在我有2 Q. 1 - 我是否应该单独应用上面的代码到每个文本框或有一个代码,我可以把所有的文本框名称的用户窗体中呢? 2-输入数据高于23:59它给出错误我改变格式为[H]:毫米,但没有工作,我想如果用户输入35:45时间显示,因为它不是像D:HH :mm