为什么excel不隐藏我的形状?

时间:2016-11-03 05:01:43

标签: excel vba macros hide basic

我在下面使用此代码...

Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)
Sub blink()
    Sleep 500
    ActiveSheet.Shapes("the_shape").Visible = False
    Sleep 500
    ActiveSheet.Shapes("the_shape").Visible = True
End Sub
我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

这很奇怪。添加DoEvents解决了这个问题。我猜测Sleep在Excel有机会隐藏形状之前暂停线程。

Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long)

Sub blink()
    Sleep 500
    ActiveSheet.Shapes("the_shape").Visible = False
    DoEvents
    Sleep 500
    ActiveSheet.Shapes("the_shape").Visible = True
End Sub