【发布时间】:2020-01-29 15:19:41
【问题描述】:
我在 excel 中有一个表格(listobject),我想在其中的某些单元格中添加 cmets。
Dim infotbl As listobject
Set infotbl = ThisWorkbook.Sheets("index").ListObjects("infotbl")
Dim myString As String
myString = "Whatever"
' this line of code works:
infotbl.ListColumns(2).DataBodyRange.item(1).Interior.color = vbGreen
' one of the next two lines of code does not work:
infotbl.ListColumns(2).DataBodyRange.item(1).AddComment
infotbl.ListColumns(2).DataBodyRange.item(1).Comment.Text Text:=myString
错误是运行错误1004 应用程序定义或对象定义错误。
我检查了 stackoverflow 中的几个帖子,其中我得到了 .AddComment 和 .comment.Text 方法,但它们不起作用。
有什么帮助吗?
谢谢
【问题讨论】:
-
iTem- 这就是你的词在 VBE 中的实际外观吗?大写已关闭。该代码对我有用。你有同名的变量吗? -
那里已经有评论了吗?
-
我同意@SJR。我猜是同名的变量或过程或模块/类等?
-
我不知道为什么 VBE 制作 iTem 而不是 Item。我搜索了“Dim ITem”并且没有这样的变量。但无论如何,足够奇怪这不是问题,因为 .iTem(1).Interior.color = vbGreen 有效,而所有其他时间我使用 .item 都不是问题。
-
感谢您的发现。我将编辑问题
标签: excel vba listobject