我正在尝试将单个单元格的文本内容转换为对该单元格的注释,然后使注释的自动大小适合内容的实际大小。我发现了两个单独的宏可以正常工作,但是在将它们组合成一个宏时遇到了麻烦。
以下代码通过将所选单元格转换为注释来工作。 https://sumtips.com/tips-n-tricks/convert-excel-cell-contents-comments-vba/
Sub ConvertToComment()
Dim C As Range
For Each C In Selection
C.ClearComments
If Len(C.Value) > 0 Then
C.AddComment
C.COMMENT.Text C.Value & ""
End If
'Optional: Delete cell content after converting
C = "See Comment"
Next C
End Sub
以下代码可用于自动调整工作表中所有注释的大小。 https://quadexcel.com/how-to-auto-size-comment-box-to-fit-its-content-in-excel/
Sub FitComments()
Dim xComment As Comment
For Each xComment In Application.ActiveSheet.Comments
xComment.Shape.TextFrame.AutoSize = True
Next
End Sub
如何将以下行合并到顶部的ConvertToComment()宏中?
xComment.Shape.TextFrame.AutoSize = True
下面的代码是我尝试添加一行,我认为这很重要,这对使其按我希望的方式工作很重要。创建评论并自动调整创建的评论的大小以适合内容。我对VBA还是很陌生。
Sub ConvertToComment()
Dim C As Range
Dim xComment As COMMENT
For Each C In Selection
C.ClearComments
If Len(C.Value) > 0 Then
C.AddComment
C.COMMENT.Text C.Value & ""
--> COMMENT.Text C.Shape.TextFrame.AutoSize = True
End If
'Optional: Delete cell content after converting
C = "See Comment"
Next C
End Sub
错误消息“对象不支持此项目或方法”