【发布时间】:2017-07-11 12:37:23
【问题描述】:
我有以下代码在用户窗体中设置文本框“txtA”的时间格式。
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]:mm 但没有工作,如果用户输入 35:45,我希望显示时间,因为它不像 d:hh:毫米
【问题讨论】:
标签: excel time-format