2017-06-02 175 views
0

我正在寫一個宏觀上的圖片(的ActiveX)的頂部添加一個形狀時,它的點擊:防止屏幕閃爍(具體情況)

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 

我發現the only way to display the shape immediately是啓用和禁用圖片:

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

然而,儘管打開屏幕更新關閉,這仍然導致屏幕刷新/ FLI克爾。任何想法如何我可以防止這一點?

回答

0

閱讀某處Visible = True/False可能會觸發重新計算工作表,這可能會導致閃爍。在您的代碼中,值得嘗試將計算設置爲手動。

+0

謝謝,但不起作用 – Absinthe