VBA Excel 复制注释包括格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19115959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 23:34:50  来源:igfitidea点击:

VBA Excel copy comment including formatting

excelvbacomments

提问by Pete855217

I'm using Excel 2007, and trying to write a VBA subroutine that will copy cell comments (including formatting). Cell comments can contain basic text formatting (style eg. bold etc) and I can successfully copy the text, but can't find a way to bring the formatting with it.

我正在使用 Excel 2007,并尝试编写一个 VBA 子例程来复制单元格注释(包括格式)。单元格注释可以包含基本的文本格式(例如粗体等样式),我可以成功复制文本,但找不到将格式带入的方法。

I was hoping I could simply define a Comments object, then set it, but no go:

我希望我可以简单地定义一个 Comments 对象,然后设置它,但不行:

Sub TestCommentCopy()

Dim r As Range
Dim c As Comment
Set r = Selection

If (Not r.Areas(1).Comment Is Nothing) Then
    Set c = r.Areas(1).Comment
End If

'Set r(1, 2).Comment = c ' Object error
'   r(1, 2).Comment = c  'Object error
'   Set r(1,2).Comment = c ' Object error
r(1, 2).ClearComments ' Works
'   r(1, 2).AddComment c 'Does not work - requires text only

r(1, 2).AddComment c.Text 'Works, but only get plain text, no formatting

End Sub

Is there a way in Excel to copy one cell's comment to another, including the formatting, not just the text?

Excel 中有没有办法将一个单元格的注释复制到另一个单元格,包括格式,而不仅仅是文本?

回答by Gary's Student

To copy formatted comments:

复制格式化注释:

Sub Macro1()
    Range("E9").Copy
    Range("L3").PasteSpecial Paste:=xlPasteComments, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
End Sub