VBA Excel复制注释,包括格式 [英] VBA Excel copy comment including formatting

查看:96
本文介绍了VBA Excel复制注释,包括格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

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

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

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

推荐答案

要复制格式的注释,请执行以下操作:

To copy formatted comments:

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

这篇关于VBA Excel复制注释,包括格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆