将变量传递给形状选择

时间:2015-10-01 09:54:39

标签: excel vba excel-vba

我正在尝试使用变量来选择某个形状并为其着色。 所以我想使用Sheet2.Shapes(varShapename)。选择选择一个形状(而不是使用形状的实际名称),然后改变它的颜色。但似乎我必须使用形状的实际名称或使用索引,我无法传递变量。

我做错了什么?

Sub KeyCellsChanged()
   Dim Cell As Object
   ' If the values in B257:D277 are greater than 0
   For Each Cell In Range("B257:D277")
   If Cell < 0 Then
   ' Make the background color of the cell the 3rd color on the
   ' current palette.
   Cell.Interior.ColorIndex = 3
   ' Select the first cell of the row, which holds the names of the shapes to change
   ActiveSheet.Cells(ActiveCell.Row, 1).Select
   Set shapeName = Selection
   Sheet2.Shapes(shapeName).Select
   Selection.ShapeRange.Fill.ForeColor.RGB = RGB(255, 0, 0)
   Else
   ' Otherwise, set the background to none (default).
   Cell.Interior.ColorIndex = xlNone

   End If
   Next Cell

End Sub

我收到运行时错误5。

1 个答案:

答案 0 :(得分:0)

而不是

shapeName = ActiveCell.Value

使用此代替

src:url(http://localhost/changingCinema/font/Soolidium.ttf) format('truetype');