使用VBA向excel添加注释

fyd*_*lio 7 excel vba comments excel-vba

我在向单元格添加注释时遇到了实际困难.

我打电话给以下子

Sub ValidationError(row As Long, column As Integer, ErrorLine As String)

Tabelle1.Cells(row, column).Interior.Color = vbYellow
Tabelle1.Cells(row, column).AddComment ErrorLine

End Sub
Run Code Online (Sandbox Code Playgroud)

但我总是得到一个1004错误,说"应用程序或对象错误"(这是翻译,原始消息:"Anwendungs-oder objektdefinierter Fehler")

该子被称为使用

Call ValidationError(8, 9, "Text string")
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

最好

Bra*_*cku 13

如果目标单元格不包含注释,则代码应该有效.您可以先更改过程以清除现有注释:

Sub ValidationError(row As Long, column As Integer, ErrorLine As String)

Tabelle1.Cells(row, column).Interior.Color = vbYellow
Tabelle1.Cells(row, column).ClearComments
Tabelle1.Cells(row, column).AddComment ErrorLine

End Sub
Run Code Online (Sandbox Code Playgroud)