Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


VBA Code to gradually increase size of picture object

Posted on 2014-02-28
Medium Priority
Last Modified: 2014-02-28
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

Question by:gabrielPennyback
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 19

Accepted Solution

Ken Butters earned 1000 total points
ID: 39896196
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

LVL 23

Assisted Solution

by:Ejgil Hedegaard
Ejgil Hedegaard earned 1000 total points
ID: 39896256
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"))

Author Comment

ID: 39896334
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 :- )


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

LVL 19

Expert Comment

by:Ken Butters
ID: 39896351
I'm not clear on the context here.... what is the escape key doing for you?

Author Closing Comment

ID: 39896493
I made some tweaks and managed to get them both to work. Thanks!

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question