Slow down SendKeys macro

M

mcwhirt3

Hello,

I have a macro that sends several sendkey commands to modify some
settings within a printer's print settings dialog box. The problem is
that the macro seems to be too fast for the application at times, and
the keys are sent before the application is at the place it needs to
be. If I print the macro and key the sequence in by hand it works
perfectly. I would like to add a quarter second delay between all the
keys that are pressed in the sequence if possible. I've examined some
loop commands, but they have resulted in much more agony than help. Any
idea on how to keep the macro from moving too fast? Thanks for any
help.
 
A

Arvin Meyer [MVP]

I would hope that you could use something else than SendKeys for program
control. SendKeys is unreliable if anything else can gain focus in Windows.
For controling a printer, you can use the PrintOut action for a macro, or
PrintOut method in VBA to control many printer dialog box settings. You can
use the PrtDev and PrtMip properties in VBA to control everything.

If you insist on using SendKeys, have a look at the sleep api:

http://www.mvps.org/access/api/api0021.htm

or if you must, reliquish control to the Operating System by using DoEvents:

For i = 1 to 5
DoEvents
Next i
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top