Solved

VBA Code to gradually increase size of picture object

Posted on 2014-02-28
5
352 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
[X]
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
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 23

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

623 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