Still can't switch focus

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
PHG-CWF
Newbie
Posts: 7
Joined: Fri Oct 22, 2010 2:42 pm

Still can't switch focus

Post by PHG-CWF » Fri Nov 05, 2010 2:45 pm

Ok, I'm a newbie and not a coder and don't want to be. I just need to get one thing automated to save me time.

This is supposed to export a report from Peachtree Accounting to Excel, then save the Excel sheet in a specific folder.

I chunked the script and ran the Peachtree and Excel parts separately and the both work perfectly.

But together, it stops working after the report is exported. After exporting, the script wont switch focus to Excel or close Peachtree.

I've tried all kinds of variations of setfocus, closewindow, waitwindow... adding waits (up 30 seconds!) nothing seems to work.

I know there's a deeper way of using API to do it, but I do not understand that at all. Help! PLEASE!


//Detect and delete inventory file before beginning
let>filename=C:\Users\Charles\Documents\My Dropbox\PHG- East Inventory\PHG-East Inventory.xlsx
IfFileExists>filename
DeleteFile>filename
endif

//Open Peachtree, enter password
run>"C:\Program Files (x86)\Sage\Peachtree\peachw.exe"
WaitWindowOpen>COMPANY NAME Log In
Send>PASSWORD
press>Enter
//WaitWindowOpen>COMPANY NAME- Peachtree Accounting

//Open Inventory Report
Press ALT
send>ri
Release ALT
Let>WF_TYPE=3
WaitWindowOpen>Select a Report or Form
//select report
press Tab
press Down
Press ralt
Send>n
Release ralt
press down*2
Press Enter
WaitWindowOpen>Modify Report - Inventory for sales reps
press enter
Press enter
wait>5

//focus on Excel
WaitWindowOpen>Microsoft Excel - Book1
SetFocus>Microsoft Excel - Book1

//select column D and set formate to currency
MouseMove>828,187
LClick
MouseMove>922,106
lclick

//save file
press lalt
send fa
Release lalt
WaitWindowOpen>Save As
send>C:\Users\Charles\Documents\My Dropbox\PHG- East Inventory\PHG-East Inventory
Press Enter

//Close Excel
WaitWindowClosed>Save As
SetFocus>Microsoft Excel - PHG-East Inventory
Press ALT
Press F4
Release ALT

//Close Peachtree
CloseWindow>Select a Report or Form
WaitWindowClosed>Select a Report or Form
setfocus>* PACIFIC HOME & GARDEN INC. - Peachtree Accounting
Press ALT
Press F4
Release ALT

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Nov 05, 2010 8:06 pm

setfocus>* PACIFIC HOME & GARDEN INC. - Peachtree Accounting
I believe the asterisk as the first character in the window_title will cause problems. It should only be used as the last character, and then only in the context of a "wild card" character.
send fa
I think you are missing the ">" character after send.
i.e. send>fa


Try adding this as the first line in your script
Let>STEP_DELAY=500

It introduces additional waits automatically. It the script works with the step _delay, then you know it's a timing issue.

Use "View System Windows" to be sure you have the window titles
coded correctly. Sometimes window titles have an invisible trailing
space character you need to account for. Using the wild card * is good for this.
WaitWindowOpen>Modify Report - Inventory for sales reps
press enter
Sometimes you need to focus a window before sending keystrokes - WaitWindowOpen will NOT focus the window.

Do this instead:

Code: Select all

WaitWindowOpen>Modify Report - Inventory for sales reps
SetFocus>Modify Report - Inventory for sales reps
Wait>0.5
press enter 

PHG-CWF
Newbie
Posts: 7
Joined: Fri Oct 22, 2010 2:42 pm

Post by PHG-CWF » Fri Nov 05, 2010 8:32 pm

Thanks.

The asterisk is part of the window name. Its some weird thing Peachtree does. And it works to open and close when only Peachtree in involved.

I added the Let>STEP_DELAY=500 and Send>fa, but it still ceases to function after the report is exported. It just stops doing anything.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Fri Nov 05, 2010 9:31 pm

Do this instead

Code: Select all

setfocus>PACIFIC HOME & GARDEN INC. - Peachtree Accounting*
Remove the asterisk from the front and put it instead at the end
(from the help file) ...looks at all windows and sets focus to the first one it finds whose title *contains* the entered text
Try using the debugger. With the script open in the editor, and the cursor on the first line of the script, press F8 to execute the script one line at a time.

PHG-CWF
Newbie
Posts: 7
Joined: Fri Oct 22, 2010 2:42 pm

Post by PHG-CWF » Sat Nov 06, 2010 4:19 pm

That did not work. I got an error saying the window did not exist. As I said, the name of the window is "* PACIFIC HOME & GARDEN INC. - Peachtree Accounting" I'm not adding the asterisk for search purposes, its part of the name.

Interestingly, when I put the asterisk back, the whole script works now. Not sure what changed, but it seems to work now. Thanks for your help!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts