首页 > 解决方案 > 尝试读取 Comment 属性时出现运行时错误 438

问题描述

在尝试获取评论的文本时(在检查评论是否存在之后)我得到

运行时错误 438“对象不支持此属性或方法”。

s = rR.Comment该过程在遇到源工作表“v”中带有注释的第一个单元格时停止。

Dim i As Long, j As Long, c As Long
Dim w As Worksheet, v As Worksheet
Dim s As String
Dim rR As Range

Set w = ThisWorkbook.Sheets(1)
Set v = ThisWorkbook.Sheets(2)
For i = 1 To 10
  For j = 1 To 10
    For c = 0 To 12
      s = ""
      Set rR = w.Cells(i, c + 7)
      With rR
        .ClearContents
        .ClearComments
        .Interior.Pattern = xlNone
        v.Cells(j, c + 4).Copy
        .PasteSpecial Paste:=xlPasteValues
        .PasteSpecial Paste:=xlPasteComments
        Application.CutCopyMode = False
        If Not .Comment Is Nothing Then
          s = rR.Comment  ' <============== ### HERE IT STOPS WITH RUN-TIME ERROR 438 ###
          If InStr(1, s, "test") > 0 Then
            .Interior.Pattern = xlSolid
            .Interior.PatternColorIndex = xlAutomatic
            .Interior.Color = 13434828
            .Interior.TintAndShade = 0
            .Interior.PatternTintAndShade = 0
          End If
        End If
      End With
      Set rR = Nothing
    Next c
  Next j
Next i

标签: excelvba

解决方案


我想你只是从头到尾都错过了.text

尝试:

s = rR.Comment.Text

推荐阅读