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?