主题
Previous (方法)
返回一个 Comment 对象,该对象代表前一条批注。
说明
本方法仅对单张工作表有效。对工作表中第一条批注使用本方法可返回 None(不是前一张工作表的最后一条批注)。
在没有现有注释的新工作簿中测试此示例。 若要清除工作簿中的所有批注,请在“即时”窗格中使用 Selection.SpecialCells(xlCellTypeComments).Delete() 。
返回值
Comment
示例
python
#本示例使用 Previous 方法导航,每隔一条删除评论
def test():
# Sets up the comments
for xNum in range(1, 10):
Application.Range("A" + xNum).AddComment()
Application.Range("A" + xNum).Comment.Text("Comment " + xNum)
print("Comments created... A1:A10")
# Deletes every second comment in the A1:A10 range
for yNum in range(10, 1, -2):
Application.Range("A" + yNum).Comment.Previous().Shape.Select(True)
Application.Selection.Delete()
print("Deleted every second comment")
python
#本示例显示 A4 单元格上一条批注的内容
def test():
print(Application.Range("A4").Comment.Previous().Text())