how can I use SendKeys statment to open aprogram and wait until the program Initializes and then send anothe sendkeys Statment to do othe thing on the opened progrma?
1- sendKeys to open document scanning program.
2- wait until it intializes.
3- sendKeys to start new scan
4- wait until finish scaning
5- send keys to save the image
The key to your problem is the waiting. With Access and SendKeys you will either have to wait a specific time (ex. 2 minutes, 2 seconds, 5 hours) or use some indicator to tell when a step is done.
With scanning is a file created? You could loop and check to see if the file was created. The problem with this is usually the file is added to the directory structure but the file has not been completely written.
Another possibility is sending all the commands at once and seeing if they all get buffered. Then the program that is scanning and copying can 'interpret" what all the keys should do.
More often than not I have to do the timing thing. Open the program, wait x seconds, sendkeys, wait x minutes, etc. Usually there is a lot of wasted time and it only works about 80% of the time.
Option Compare Database
'***************** Code Start ******************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'Code Courtesy of
Private Const STARTF_USESHOWWINDOW& = &H1
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Public Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
Public Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
Public Sub ShellWait(Pathname As String, Optional WindowStyle As Long)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret As Long
' Initialize the STARTUPINFO structure:
.cb = Len(start)
If Not IsMissing(WindowStyle) Then
.dwFlags = STARTF_USESHOWWINDOW
.wShowWindow = WindowStyle
' Start the shelled application:
ret& = CreateProcessA(0&, Pathname, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
'***************** Code End ****************