使用 VBA 向 excel 添加注释
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28494788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding a comment to a excel using VBA
提问by fydelio
I'm having real difficulties adding a comment to a cell.
我在向单元格添加评论时遇到了真正的困难。
I'm calling the following sub
我打电话给以下子
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
But I always get a 1004 error, saying "Application or object error" (this is translated, original message: "Anwendungs- oder objektdefinierter Fehler")
但是我总是收到1004错误,说“应用程序或对象错误”(这是翻译过来的,原消息:“Anwendungs-oder objektdefinierter Fehler”)
The sub is called using
子被称为使用
Call ValidationError(8, 9, "Text string")
What am I doing wrong?
我究竟做错了什么?
Best
最好的事物
回答by BrakNicku
Your code should work if the target cell does not contain a comment. You can change the procedure to clear existing comments first:
如果目标单元格不包含注释,您的代码应该可以工作。您可以更改程序以先清除现有注释:
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

