简体   繁体   English

宏未选择 Excel 中注释更改的范围

[英]Macro not selecting range for comment change in Excel

I am trying to write a macro for Excel 2010 that will take a user selection of a cell or range of merged cells and unbold the comment and add a pattern.我正在尝试为 Excel 2010 编写一个宏,它将让用户选择一个单元格或合并单元格范围,并取消注释的粗体并添加一个模式。

Sub commentstripe()
'
' commentstripe Macro
'
'
    Dim myRange As Range
    Set myRange = Range(Selection.Address)
    myRange.Comment.Shape.TextFrame.Characters.Font.Bold = False
    With myRange.Interior
        .Pattern = xlLightUp
        .PatternColorIndex = xlAutomatic
        .PatternTintAndShade = 0
    End With
    ActiveWorkbook.Save
End Sub

It seems to be hanging on the myRange.comment line but I can't seem to figure out why.它似乎挂在 myRange.comment 行上,但我似乎无法弄清楚原因。 I'm running it from a shortcut, Ctrl+Shift+A.我从快捷键 Ctrl+Shift+A 运行它。 Any advice would be appreciated.任何意见,将不胜感激。

Regards, Sandy问候, 桑迪

I don't see why it would hang... except for the fact that if there's no comment in the cell, it will throw an error.我不明白为什么它会挂起......除了如果单元格中没有评论,它会抛出一个错误。 Also, if this is a new workbook, and you just save it, it will throw a warning saying this is an excel file, not a macro-enabled excel file.此外,如果这是一个新工作簿,而您只是保存它,它会发出警告,指出这是一个 excel 文件,而不是启用宏的 excel 文件。 Just for you to know.只为让你知道。

I commented the save line and everything worked perfectly.我评论了保存行,一切正常。

EDIT: See if this works编辑:看看这是否有效

Sub commentstripe()

Dim myRange As Range
Set myRange = Selection
myRange.Cells(1, 1).Comment.Shape.TextFrame.Characters.Font.Bold = False
With myRange.Interior
    .Pattern = xlLightUp
    .PatternColorIndex = xlAutomatic
    .PatternTintAndShade = 0
End With
ActiveWorkbook.Save
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM