VBA Excel:Cells.Value上的错误400

时间:2015-01-15 09:04:46

标签: excel vba excel-vba

我在以下函数中的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工作正常。

1 个答案:

答案 0 :(得分:1)

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