当我执行ADD按钮时,我收到一条错误消息:运行时错误' -2147417848(80010108)':方法'添加'对象' listrows'失败但是,如果我删除" ListBox2"表格工作正常。任何帮助将不胜感激。
这是VBA代码:
Private Sub AddExpenses_Click()
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
If StaffName = "" Then
MsgBox "Vendor NAME cannot be empty.."
StaffName.SetFocus
Exit Sub
ElseIf ClientName = "" Then
MsgBox "GL ACCOUNT cannot be empty.."
ClientName.SetFocus
Exit Sub
ElseIf FoodDrink = "" Then
MsgBox "Total Invoice Amount cannot be empty.."
FoodDrink.SetFocus
Exit Sub
End If
'If CheckForErrors > 0 Then Exit Sub
Set ws = Sheets("Expense Report")
ws.Activate
ActiveSheet.ListObjects("Expenses").ListRows.Add
ModifyTableRow ExpensesTable.ListRows(ExpensesTable.ListRows.Count).Range
ChangeRecord_SpinDown
UpdatePositionCaption
Call calcul
ListBox2 = "expenses"
Worksheets("expense report").Activate
ThisWorkbook.Save
End Sub
Sub ModifyTableRow(TableRow As Range)
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Worksheets("expense report").Select
Selection.Activate
Misc = ""
PriorHST = ""
TableRow.Select
Selection.Activate
With TableRow
MsgBox "The last ROW is: " & TableRow.Address
.Cells(1, 1) = Calendar1.Value
.Cells(1, 3) = StaffName.Value
.Cells(1, 5) = ClientName.Value
.Cells(1, 6) = Description.Value
'.Cells(1, 7) = ReceiptsYes.Value
'.Cells(1, 7) = ReceiptsNo.Value
.Cells(1, 8) = Airfare.Value
.Cells(1, 9) = Accommodation.Value
.Cells(1, 10) = GroundTransport.Value
.Cells(1, 11) = FoodDrink.Value
If ReceiptsYes.Value = True Then
.Cells(1, 7) = "Yes"
Else
.Cells(1, 7) = "No"
End If
Application.Calculation = xlCalculationAutomatic
Misc = .Cells(1, 12)
Misc = Format(Misc, "$#,##.00")
PriorHST = .Cells(1, 13)
PriorHST = Format(PriorHST, "$#,##.00")
End With
Application.Calculation = xlCalculationManual
End Sub