从单元格中拉出颜色方案并应用于宏

时间:2016-06-22 18:12:13

标签: vba excel-vba excel

我有一个宏来覆盖评论指标(通常为红色),以便它与细胞的颜色融为一体。我想知道我需要对这个宏做什么补充,以便它从引用的单元格中拉出颜色方案并将该值放在颜色方案中?

Option Explicit

Sub CoverCommentIndicator()
Dim ws As Worksheet
Dim cmt As Comment
Dim rngCmt As Range
Dim shpCmt As Shape
Dim shpW As Double 'shape width
Dim shpH As Double 'shape height

Set ws = ActiveSheet
shpW = 6
shpH = 4

For Each cmt In ws.Comments
  Set rngCmt = cmt.Parent
  With rngCmt
    Set shpCmt = ws.Shapes.AddShape(msoShapeRightTriangle, _
      rngCmt.Offset(0, 1).Left - shpW, .Top, shpW, shpH)
  End With
  With shpCmt
    .Flip msoFlipVertical
    .Flip msoFlipHorizontal
    .Fill.ForeColor.SchemeColor = 10
    .Fill.Visible = msoTrue
    .Fill.Solid
    .Line.Visible = msoFalse
  End With
Next cmt

2 个答案:

答案 0 :(得分:1)

不要在单元格中添加形状并尝试匹配单元格颜色,只需将注释添加为数据验证下的输入消息即可。然后,当您选择单元格时,将显示您的注释,但单元格中没有放置指示符。

如果需要使用宏执行此操作,可以使用单元格的.Validation.InputMessage属性来设置输入消息。使用宏录制器尝试一次,然后根据需要修改代码。

答案 1 :(得分:0)

这应该涵盖它:

.Fill.ForeColor.SchemeColor = cmt.Parent.Interior.ColorIndex + 2 ' + 2 just a number to let the color be different from the color index in the cell

此外,我认为你可以为此定义enum the colors是一个好主意。