Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attachmate AppActivate Problem

Status
Not open for further replies.

camprunamuk

Technical User
Jul 22, 2002
3
0
0
US
I am using macros in Attachmate to display a series of text files in Notepad. Previously, a user would have to close Notepad and then trigger the macro to ask for the next file. I am now trying to add an automatic close into the macro using the following code:
AppActivate "TempEDI1 - Notepad"
SendKeys "%{F4}", True
DoEvents
Later in the code, I re-activate Attachmate and continue as before. The good news is that it works most of the time...that's also the bad news! This fails once per day in only one scenario: The second time that the macro is triggered since initial start-up or re-start, the Notepad button on the Windows toolbar highlights, but does not depress and the Notepad does not receive focus. The Alt+F4 gets sent to the Attachmate window and it tries to close. Since this happens during the macro, we get an error message that says "You can't exit while a macro is running." Then the macro runs perfectly for the remainder of the day (300-500 more times!). I would have expected this to fail when the targeted file wasn't open in Notepad, but it doesn't even try when that is the case.
Any help anyone can offer would be greatly appreciated. Thanks!
 
AppActivate and Sendkeys are quirky at best, but it sounds like you've got this working pretty well for the most part. Are you using EB to launch the Notepad application? If so you may be setting focus with the app launch.

I usually use rc% = Shell("notepad.exe MyFile.txt",1)

The WindowStyle option has these values:
1 Normal window with focus
2 Minimized with focus
3 Maximized with focus
4 Normal window without focus
7 Minimized without focus
If windowstyle% is omitted, it defaults to 1.

Hope this helps,

calculus
 
Thanks for the advice. In answer to your question, I am aware of the code you supplied with the Shell command. It's exactly what is used much later in the code to open the new document after the first document is closed. I am using WindowStyle 1 for the new document. Attachmate must receive focus before this process begins because a toolbar button is clicked to fire the macro in the first place.

Do you know if there is any another way to make reference to a currently open window w/o using AppActivate and SendKeys? Or a way to return a value if AppActivate fails?

What seems odd is that the "Alt+F4" doesn't try to close the Attachmate window when Notepad isn't open at all(which is where I actually expected to run into this error). In that situation, the program seems to look for Notepad, realize that Notepad isn't open and simply "skips" the "Alt+F4" SendKeys command. Instead, it seems to "hang" on the second attempt and then never again for the rest of the day - or at least until the next re-start.

Any other ideas?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top