简体   繁体   中英

Adding a comment to a excel using VBA

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")

The sub is called using

Call ValidationError(8, 9, "Text string")

What am I doing wrong?

Best

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM