Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

VBA Code to gradually increase size of picture object

This code works perfectly as long as I hit "Esc" shortly after clicking on its button. I thought that SendKeys "{ESC}" either at the end of the macro or within each iteration might work but of course it doesn't. How do I emulate that within the code itself?

I've been googling how to set up a pause/resume timer kind of thing but haven't found anything that works yet.

For i = 1 To 10
    ActiveSheet.Shapes.Range(Array("Picture 5")).ScaleWidth 1.1, msoFalse, msoScaleFromBottomleft
    ActiveSheet.Shapes.Range(Array("Picture 5")).ScaleHeight 1.1, msoFalse, msoScaleFromBottomleft
    Application.Wait ("00:00:01")
    SendKeys "{ESC}"
Next i

Open in new window

Thanks,
John
0
gabrielPennyback
Asked:
gabrielPennyback
  • 2
  • 2
2 Solutions
 
Ken ButtersCommented:
I've used this before... works well.

put this at the top of your module prior to any function or sub.
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Open in new window

Then as an example to sleep for 5 seconds:
Sleep 5000

Open in new window

0
 
Ejgil HedegaardCommented:
Wait use absolute time, so "00:00:01" means wait until 1 second after midnight.
Use this to wait 1 second
Application.Wait (Now + TimeValue("0:00:01"))
0
 
gabrielPennybackAuthor Commented:
Sleep 100 works if I step through it (it's jerky of course), but not if I run it. Both sleep  and Wait work if you manually hit the Esc key at any time.

Could someone please post a solution in the context of my whole code, I may be putting things in the wrong place. Or best of all, code that truly emulates hitting the Exc key :- )

Thanks,
John

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub TimeReveal()
For i = 1 To 10
    ActiveSheet.Shapes.Range(Array("Picture 6")).ScaleWidth 1.1, msoFalse, msoScaleFromBottomleft
    ActiveSheet.Shapes.Range(Array("Picture 6")).ScaleHeight 1.1, msoFalse, msoScaleFromBottomleft
    'Application.Wait (Now + TimeValue("0:00:01"))
    Sleep 100
Next i
End Sub

Open in new window

0
 
Ken ButtersCommented:
I'm not clear on the context here.... what is the escape key doing for you?
0
 
gabrielPennybackAuthor Commented:
I made some tweaks and managed to get them both to work. Thanks!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now