Solved

VBA Code to gradually increase size of picture object

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

914 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

13 Experts available now in Live!

Get 1:1 Help Now