【发布时间】:2017-04-30 00:20:51
【问题描述】:
使用带有宏的excel的员工登录系统。 员工将输入员工 ID,然后在 txtName 中显示他们的姓名。如果他们点击登录按钮,我希望能够捕获登录时间并将其粘贴到 Excel 表中,然后在他们注销时反之亦然。
到目前为止的代码如下:
Dim CM As Boolean
Private Sub txtEmpID_Change()
Dim mySheet As Worksheet
Dim myRange As Range
Set mySheet = Sheets("Emp_ID")
Set myRange = mySheet.Range("B:B").Find(txtEmpID.Value, , , xlWhole)
If Not myRange Is Nothing Then
txtName.Value = myRange.Offset(0, -1)
Else
txtName.Value = "Match not found"
End If
End Sub
Private Sub UserForm_activate()
Do
If CM = True Then Exit Sub
txtTime = Format(Now, "hh:mm:ss")
DoEvents
Loop
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
CM = True
End Sub
【问题讨论】:
-
您可以在
CommandButton_Click例程中发布代码,因为这是我们需要能够帮助您的部分。您可以简单地编辑这个问题,而不是开始一个新问题。