VBA Excel:错误400 Cells.Value上

在下面的函数中,我得到了Cells.Value上的一个400错误:

Function Add_Buttons(myColumn) Dim btn As Button ActiveSheet.Buttons.Delete Dim t As Range 'Search for last row lastRow = Cells(Rows.Count, 1).End(xlUp).Row 'Force-Update Application.Calculate 'Generate a button for each cell, if it's not empty For i = 3 To lastRow Set t = Range(Cells(i, myColumn), Cells(i, myColumn)) If Cells(i, t.column - 1).Text = "Nicht OK" Then Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.RowHeight) With btn .OnAction = "'DieseArbeitsmappe.Update_DB """ & ActiveSheet.Cells(i, myColumn).Value & """'" 'THIS IS WHERE THE ERROR OCCURS .Caption = "Update" .Name = "Btn_" & ActiveSheet.Name & "_" & i End With End If Next i End Function 

我在代码中找不到任何错误。 它明确地与ActiveSheet.Cells(i, myColumn).Value ,因为没有这个参数, .OnAction工作正常。

我得到了它的工作。 如果您有类似的情况,请确保您单元格中的引号已经被转义。 这样你可以避免这个错误。