我创建了一个简单的用户表单,它在2013年之后与excel版本配合使用。但是当在excel 2010版本中运行时,它一直给我错误。
这是我的用户表单代码
Private Sub CloseButton_Click()
Unload Me
End Sub
Private Sub ClearButton_Click()
Call UserForm_Initialize
End Sub
Private Sub UserForm_Initialize()
'Clear Form
'Clear ProjectList
ProjectList.Clear
'Fill ProjectList
With Worksheets("Database")
ProjectList.List = .Range("Q3:Q" & .Range("Q" & .Rows.Count).End(xlUp).Row).Value
End With
'Clear NationalityList
NationalityList.Clear
'Fill NationalityList
With Worksheets("Database")
NationalityList.List = .Range("H3:H" & .Range("H" & .Rows.Count).End(xlUp).Row).Value
End With
'Clear NationalityList
WorkPermitList.Clear
'Fill WorkPermitList
With Worksheets("Database")
WorkPermitList.List = .Range("J3:J" & .Range("J" & .Rows.Count).End(xlUp).Row).Value
End With
'Clear TransferFromList
TransferFromList.Clear
'Fill TransferFromList
With Worksheets("Database")
TransferFromList.List = .Range("D3:D" & .Range("D" & .Rows.Count).End(xlUp).Row).Value
End With
'Clear TransferToList
TransferToList.Clear
'Fill TransferToList
With Worksheets("Database")
TransferToList.List = .Range("D3:D" & .Range("D" & .Rows.Count).End(xlUp).Row).Value
End With
'Clear LastPositionList
LastPositionList.Clear
'Fill LastPositionList
With Worksheets("Database")
LastPositionList.List = .Range("E3:E" & .Range("E" & .Rows.Count).End(xlUp).Row).Value
End With
'Clear CurrentPositionList
CurrentPositionList.Clear
'Fill CurrentPositionList
With Worksheets("Database")
CurrentPositionList.List = .Range("F3:F" & .Range("F" & .Rows.Count).End(xlUp).Row).Value
End With
'Clear Certificates
cert1list.Clear
cert2list.Clear
cert3list.Clear
cert4list.Clear
cert5list.Clear
cert6list.Clear
cert7list.Clear
'Fill CurrentPositionList
With Worksheets("Database")
cert1list.List = .Range("R3:R" & .Range("R" & .Rows.Count).End(xlUp).Row).Value
cert2list.List = .Range("R3:R" & .Range("R" & .Rows.Count).End(xlUp).Row).Value
cert3list.List = .Range("R3:R" & .Range("R" & .Rows.Count).End(xlUp).Row).Value
cert4list.List = .Range("R3:R" & .Range("R" & .Rows.Count).End(xlUp).Row).Value
cert5list.List = .Range("R3:R" & .Range("R" & .Rows.Count).End(xlUp).Row).Value
cert6list.List = .Range("R3:R" & .Range("R" & .Rows.Count).End(xlUp).Row).Value
cert7list.List = .Range("R3:R" & .Range("R" & .Rows.Count).End(xlUp).Row).Value
End With
'Clear Action List
NameText.Value = " "
ContactNumber.Value = " "
Age.Value = " "
DOB.Value = " "
NRIC.Value = " "
ECSOC.Value = " "
DDJV.Value = " "
'Uncheck DataCheckBoxes
CheckBox1.Value = False
CheckBox2.Value = False
End Sub
Private Sub SubmitButton_Click()
Dim emptyRow As Long
'Make Sheet1 active
Sheet3.Activate
ActiveSheet.Unprotect "eastmarine123"
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("c:c")) + 1
'Crew Transfer information
Cells(emptyRow, 5).Value = ProjectList.Value
Cells(emptyRow, 6).Value = NameText.Value
Cells(emptyRow, 7).Value = ContactNumber.Value
Cells(emptyRow, 8).Value = Age.Value
Cells(emptyRow, 9).Value = DOB.Value
Cells(emptyRow, 10).Value = ECSOC.Value
Cells(emptyRow, 11).Value = DDJV.Value
Cells(emptyRow, 12).Value = NationalityList.Value
Cells(emptyRow, 13).Value = WorkPermitList.Value
Cells(emptyRow, 14).Value = TransferFromList.Value
Cells(emptyRow, 15).Value = TransferToList.Value
Cells(emptyRow, 16).Value = NRIC.Value
Cells(emptyRow, 17).Value = LastPositionList.Value
Cells(emptyRow, 18).Value = CurrentPositionList.Value
'OptionBox & CheckBox
If OptionButton1.Value = True Then Cells(emptyRow, 19).Value = OptionButton1.Caption
If OptionButton2.Value = True Then Cells(emptyRow, 20).Value = OptionButton2.Caption
If CheckBox1.Value = True Then Cells(emptyRow, 21).Value = CheckBox1.Caption
If CheckBox2.Value = True Then Cells(emptyRow, 22).Value = CheckBox2.Caption
'Certificate List
Cells(emptyRow, 23).Value = cert1list.Value
Cells(emptyRow, 24).Value = cert2list.Value
Cells(emptyRow, 25).Value = cert3list.Value
Cells(emptyRow, 26).Value = cert4list.Value
Cells(emptyRow, 27).Value = cert5list.Value
Cells(emptyRow, 28).Value = cert6list.Value
Cells(emptyRow, 29).Value = cert7list.Value
'Register current date and time
Cells(emptyRow, 3).Value = Date
Cells(emptyRow, 4).Value = Time
ActiveSheet.Protect "eastmarine123", True, True
ThisWorkbook.Save
End Sub
当我运行调试时,它会在这两个"日期"以及"时间"
上给出错误Cells(emptyRow, 3).Value = Date
Cells(emptyRow, 4).Value = Time
当我删除这两行时,它运行正常。我认为日期和时间功能假设在整个办公室版本中兼容?