Solved

VBA Code to gradually increase size of picture object

Posted on 2014-02-28
5
333 Views
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

Thanks,
John
0
Comment
Question by:gabrielPennyback
  • 2
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 250 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

0
 
LVL 21

Assisted Solution

by:Ejgil Hedegaard
Ejgil Hedegaard earned 250 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"))
0
 
LVL 1

Author Comment

by:gabrielPennyback
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 :- )

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
 
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?
0
 
LVL 1

Author Closing Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now