0

I'm writing a macro to add a shape on top of a picture (ActiveX) when it's clicked on:

Private Sub clickpic_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single)

ClickShape CLng(x), CLng(y)

End Sub

Public addedShapes() As Shape
Public sIndex As Integer

Sub ClickShape(x As Long, y As Long)

Dim shp As Shape

Application.ScreenUpdating = False

Set shp = ActiveSheet.Shapes.AddShape(msoShapeMathMultiply, x + ActiveSheet.Shapes("clickpic").Left - 10, _
y + ActiveSheet.Shapes("clickpic").Top - 10, 20, 20)

With shp.Fill

    .ForeColor.RGB = RGB(255, 0, 0)
    .backColor.RGB = RGB(255, 0, 0)

End With

shp.Line.Visible = False

shp.Name = CStr(shp.Top & shp.Left)

ReDim Preserve addedShapes(sIndex)
sIndex = sIndex + 1

Set addedShapes(UBound(addedShapes)) = shp

ActiveSheet.Shapes("clickpic").Visible = False
ActiveSheet.Shapes("clickpic").Visible = True

Application.ScreenUpdating = True

End Sub

I've found the only way to display the shape immediately is to enable and disable the picture:

ActiveSheet.Shapes("clickpic").Visible = False
ActiveSheet.Shapes("clickpic").Visible = True

However, despite turning screen updating off this still causes the screen to refresh / flicker. Any idea how I can prevent this?

Community
  • 1
  • 1
Absinthe
  • 3,258
  • 6
  • 31
  • 70

1 Answers1

0

Read somewhere that Visible = True/False may trigger recalculation of the sheet, which may cause the flicker. It's worth trying to set calculation to manual during your code.

Basic
  • 1
  • 3