Excel 2003 interacting with another program

S

Steve

I would like to program Excel 2003 to interact with a particular window in
another program. Essentially it would have to call the other window (already
open), send Alt-letter, tab or Enter command(s) to control its Menu, wait for
the program to change in response to the command(s), copy a string from Excel
and paste it in the other program, send Alt-letter, tab or Enter command(s)
to the program, wait for the other program to respond, send additional
Alt-letter, tab or Enter commands with short pauses in-between (one of which
is copy to clipboard), and finally return control to Excel, paste what was
copied to the clipboard by the other program, then loop to repeat with
another string from Excel and other data returned from the program.

Right now the Excel part is done with a macro, but while the other program
window is the focus it is all manual.

Is it possible to do this? The other program may have more than one window
open so how do I specify the particular window in am interacting with?
Depending on network traffic the speed of the other program's response may
vary (to respond to commands or to produce the data), so how can Excel sense
the changes that I would see as the other program responds, so it would know
when to send or do the next thing?
 
J

Joel

To activate another window you will need to use the following

AppActivate title where title is the tile of the window where the 2nd
program is running


To send keys strokes to another window use the following

expression.SendKeys(Keys, Wait)


See VBA help on how to use the functions.
 
J

Joel

Another possiblitly is if the application is web based . You can open an
Internet explorer application and through VBA code retrieve all the data you
need. This is probably the better approach.

Exel can also open other Microsfot Office Products and retrieve data. Or
you can export the data from other applications to text files like CSV to get
the data.
 
J

Jacob Skaria

Hi Steve

--In order to check whether the the other applicaiton is open or not you can
use FindWindow

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

lnRetVal = FindWindow("NOTES", vbNullString)
If lnRetVal = 0 Then
MsgBox "Application must be open", vbInformation, "App-Name"
Exit Sub
End If

--To activate the window you can use AppActivate

AppActivate "Window caption"

--You can use SendKeys for tab and even for typing a text to the other
application
SendKeys "%F", True
SendKeys "A", True
'GSSWait
SendKeys CStr("c:\imagepro\g\" & arrAttach(x) & ".doc"), True
AppActivate "Create Attachments"
SendKeys "%R", True

--You will have do a lot of testing and put stoppers in between to deal
with the traffic and other programs response...In the above GSSWait is a
procedure to wait for a certain time....Again you will have to adjust the
wait time in between activities...(but the key point is with a lot of testing
and fine tuning you CAN...)


If this post helps click Yes
 
S

Steve

Looks like what I need, except one additional question >

Rather than just waiting and setting the wait for the worst possible case,
is there any way to

1) Test if the other application window has changed?

and even...

2) Check for the first five or ten characters of text in the other window?
 

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