在Excel里,怎么用VBA编程实现每隔几秒循环更换图片?

2025-01-02 20:51:12
推荐回答(2个)
回答1:

图片层代码

Private Sub UserForm_Click()

Do While i < 100

a = i Mod 5

Image1.Picture = LoadPicture("C:\Documents and Settings\xd\My Documents\My Pictures\" & a & ".jpg") '加载图片

Delay 5

i = i + 1

Loop

End Sub


模块层代码

Private Declare Function timeGetTime Lib "winmm.dll" () As Long

'延时

Public Sub Delay(ByVal num As Integer)

Dim t As Long

t = timeGetTime

Do Until timeGetTime - t >= num * 1000

DoEvents

Loop

End Sub

效果如图

回答2:

vba没有time控件,你又是单进程的。你这样了需要一个无限循环的进程一直执行下去。请问,想过怎么退出没?