【发布时间】:2017-07-14 05:25:18
【问题描述】:
我在下面的代码中收到对象所需的运行时错误,我检查了工作表名称它们是否正确但仍然显示相同的错误 Sheet1.Range("A1").Value = Date & " " & Time
Private Sub CommandButton1_Click()
Dim username As String
Dim password As String
username = TextBox1.Text
password = TextBox2.Text
Dim info
info = IsWorkBookOpen("D:\TMS_Project\username-password.xlsx")
If info = False Then
Workbooks.Open ("D:\TMS_Project\username-password.xlsx")
End If
Dim x As Integer
x = 2
Do While Cells(x, 1).Value <> ""
If Cells(x, 1).Value = username And Cells(x, 2).Value = password Then
MsgBox "Welcome!"
Sheet1.Range("A1").Value = Date & " " & Time
Selection.NumberFormat = "m/d/yyyy h:mm AM/PM"
UserForm1.Hide
ActiveWorkbook.Close True
End
Else
x = x + 1
End If
Loop
MsgBox "Please check your username or password!"
ActiveWorkbook.Close True
TextBox1.Text = ""
TextBox2.Text = ""
TextBox1.SetFocus
End Sub
【问题讨论】:
-
它是
Sheet1CodeName,不一定是您的工作表名称,对吧? -
我想我解决了 worksheets("Sheet1").Range("A1").Value = Date & " " & Time
-
@shai 你说的也对..我会这样尝试