使用VBA添加Excel单元格批注异常:箭头红且审阅栏不显示
问题原因
Excel目前存在两种批注体系:
- 传统批注(Comment):通过VBA的
.AddComment创建,箭头默认红色,不会出现在「审阅」选项卡的「显示批注」列表中,仅能通过鼠标悬停查看。 - 线程批注(Threaded Comment):手动添加的批注属于此类,箭头默认紫色,会在「审阅」选项卡的「显示批注」中展示,支持回复等功能。
你的代码使用.AddComment创建了传统批注,这就是导致差异的核心原因。
解决方案
推荐使用线程批注替代传统批注,以下是修改后的代码:
Sub AddThreadedComments() Dim rCell As Range, rEnd As Range, strNote As String, rLookupTable As Range Dim wsPortolio As Worksheet, wsTracker As Worksheet Set wsPortolio = Worksheets("Stock List") Set wsTracker = Worksheets("Tracking") Set rLookupTable = wsPortolio.Range("A3:H100") With wsTracker.Range("A3:A100") Set rEnd = .Find(What:="End", LookIn:=xlValues) End With For Each rCell In wsTracker.Range("A3:A" & rEnd.Row - 1) With rCell ' 处理VLookup可能的错误(找不到匹配项时返回空) On Error Resume Next strNote = Application.VLookup(rCell.Value, rLookupTable, 8, False) On Error GoTo 0 ' 删除已有的线程批注和旧版批注 Do While .ThreadedComments.Count > 0 .ThreadedComments(1).Delete Loop If Not .Comment Is Nothing Then .Comment.Delete ' 非空时添加线程批注 If strNote <> "" Then .AddThreadedComment strNote End If End With Next End Sub
额外优化点
- 增加了VLookup的错误处理,避免找不到股票代码时抛出错误;
- 先清理目标单元格已有的所有批注(线程+传统),避免重复添加;
- 仅当笔记内容非空时才添加批注,避免创建空批注;
- 使用
rCell.Value作为VLookup的查找值,逻辑更严谨。
内容的提问来源于stack exchange,提问作者westinq
相关产品推荐
相关产品推荐

