I am attempting to automate a data entry task. It starts as we receive an email in Outlook from a partner company, then is printed out and hand entered into our customer record system. Not only is this super lame, but the email prints out to 2 pages where half of the order is on the 2nd page. I wrote a script that Opens up the email and Sends the key commands the crawl down through the email, deleting empty lines and formatting the fonts and sizes to make data entry easier. Got the script up and running, and was feeling ambitious, and wanted to try to Copy all of that lovely data to a AHK Var Array, and then have AHK transfer clean data to our CRM Onyx. The problem is as my script gets longer it starts to become unreliable, like it doesn't have enough time to wait for Outlook to finish a step before going on to the next. I tried to add additional sleep time and that helped but it now breaks down in random places and becomes unusable and is driving me nuts, because I know it works in baby steps but the more I do the greater the random failures happen. Like I have #1 hotkey that deals with just the email, and I get it to work perfect, but then as I am building the next #2 hotkey, and go back to use #1, it is like all the timing and sleeps are thrown off. Here is a taste of my #1 code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
SetTitleMatchMode, 2
WinGet, Onyx, List, Onyx Employee Portal - Web Client - Windows Internet Explorer
SetBatchLines, 20ms
; Was a Loop command for 2 Address line regs. Now saves reg info into a Var Array to automate DP. Must watch the process and send a pause
hotkey CTRL+Shift+Z when a 3 Address Line reg is encountered. Also a Pause at the end of a batch. Background processes that eat a bit of
CPU resources can easily throw off this Macro. Be ready to CTRL+Shift+Z to reset the macro. To Activate CRTL+SHIFT+o (o as in Oscar)
^+o::
KeyWait, o
Process, Priority, , High
WGU_Address_Line_2 := ;
Sleep 600
Send {Enter}
Sleep 250
Send {Alt}{Down}{Tab 6}
Sleep 1000
Send {Enter}{Down}{Enter}
Sleep 750
Send {Del 3}{Down}{Del 7}{Down}{Del 5}{Down 5}{Del 10}{Down 3}{Del 10}{Down}{Del 10}{Down}{Del 10}{Down}{Del 5}+^{Home}
; Highlight Top Paragraph
Sleep 500
Send {Alt}
Sleep 100
Send {Right 3}{Down}{Tab 6}8{Enter}{Home}{Down 14}
; Reduce Top Paragraph Size
Send {End}+^{Up}
; Highlight Student Name
Sleep 750
Send {ALT}{Down}
Sleep 1000
Send {Tab 6}16{Enter}
Sleep 100
Send {Home}{Right 14}^+{Right}+{Left}^{c} ;Copy WGU student First Name
Sleep 250
WGU_First_Name := Clipboard
Sleep 100
Send {Right 2}+{End}^c ;Copy WGU student Last Name
Sleep 250
WGU_Last_Name := Clipboard
Sleep 100
Send {Home}{Down}{Del 5}{Down}{End}+^{Up}
; Highlight Student Email
Sleep 750
Send {Alt}
Sleep 100
Send {Down}
Sleep 750
Send {Tab 6}16{Enter}{Home}
Sleep 100
Send {Right 15}+{End}^{c} ;Copy WGU student Email Address
Sleep 100
WGU_Email_Address := Clipboard
Sleep 250
Send {Home}{Down}{Del 5}{Down}{End}+^{Up}
Sleep 100
; Highlight Student ID
Sleep 750
Send {Alt}
Sleep 250
Send {Down}
Sleep 750
Send {Tab 6}16{Enter}{Home}{End}+{Left 4} ;Highlight last 4 digits of Student ID
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 17}{Enter 2} ;Color last 4 digits of Student ID
Sleep 100
Send {Home}{Right 20}+{End}^{c} ;Copy WGU Student ID#
Sleep 250
WGU_Student_ID := Clipboard
Sleep 100
Send {Home}{Down}{Del 5}{Down 2}{Del 10}{Down}{Del 10}{Down 2}{Del 10}+^{Up 4} ; Highlights the 4 lines of Mentor Info Block
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 6}8{Enter}{Home}{Down 5}{End}+^{Up} ;Reduce the size of the Mentor Info Block
;; Highlight Address Line 1
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 6}16{Enter}
Sleep 500
Send {Home}{Right 8}+{End}^{c} ;Copy Address Line #1
Sleep 250
WGU_Address_Line_1 := Clipboard
Sleep 2500 ;Last Chance to interrupt script to run alternate script for a 3 address line reg.
Send {Down}{Del}{Space 8}{End}+^{Up}
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 6}16{Enter}{Home} ;Highlight and fix Address Line 2 (City, State, Zip)
Sleep 100
Send {Right 8}^+{Right}+{Left}^{c} ;Copy City
Sleep 250
WGU_City := Clipboard
Sleep 100
Send {Right 2}+^{Right}^{c} ;Copy State
Sleep 250
WGU_State := Clipboard
Sleep 100
Send {Right 3}+{End}^{c} ;Copy Zip
Sleep 250
WGU_Zip := Clipboard
Sleep 100
Send {Home}{Down}{Del 5}{Down}{End}+^{Up} ;Hightlight Phone Number
Sleep 750
Send {Alt}{Down}
Sleep 750
Send {Tab 6}16{Enter}{Home}
Sleep 100
Send {Right 22}+^{Right}^{c} ; Copy Telephone number 1 of 3 parts
Sleep 250
WGU_Phone_1of3 := Clipboard
Sleep 100
Send {Right 2}+^{Right}^{c} ; Copy Telephone number 2 of 3 parts
Sleep 250
WGU_Phone_2of3 := Clipboard
Sleep 100
Send {Right 2}+{End}^{c} ; Copy Telephone number 3 of 3 parts
Sleep 250
WGU_Phone_3of3 := Clipboard
Sleep 100
Send {Home}{Down 2}{Del 5}{Down}{Del 2}{Space 8} ;Course Name
Sleep 100
Send {Right 13}+{End}+{Left 6}^{c} ;Copy Course Name
Sleep 250
WGU_Course_Reg := Clipboard
Sleep 100
; Clean up remainder of Email
Send {Home}{Down}{Del 10}{Down}{Del 10}{Down}{Del 10}{Down}{Del 20}{Down}{Del 10}{Down}{Del}{Down}{Del}{Down}{Del 10}{Down}{Del}{Down}
Sleep 250
If (WGU_Course_Reg= "Classroom Mgt for New Teachers/Motivating Today's Learner")
Send WGU-CMNT TC216
else
If (WGU_Course_Reg= "Designing Curriculum and Instruction and Building Your Repertoire of Teaching Strategies")
Send WGU-DCI/IMS/BYRT TC217
else
If (WGU_Course_Reg= "Designing Assessment to Promote Learning")
Send WGU-DAP TC218
else
If (WGU_Course_Reg= "Reading: Part One/Foundations; Part Two/Teaching Reading in the Elem. Grades")
Send WGU-FRL TC219
else
If (WGU_Course_Reg= "MATH: Teaching for Understanding")
Send WGU-MATH TC220
else
Sleep 250
Send +{Home}{Alt}{Down}
Sleep 750
Send {Tab 6}28{Enter} ;Increase Font Size
Sleep 250
Send {Alt}{Down}
Sleep 750
Send {Tab 28}{Enter}^{b} ;Center & Bold
;Sleep 250
;Send ^s ;Save Reg
;Sleep 1000
;Send ^p ;Print Reg
;Sleep 500
;Send {Enter}
;Sleep 1500
;Send !{F4} ;Close reg
;Sleep 500
;Send {Down} ;Move Down in Outlook folder
returnAnd here is #2
; Test Macro to populate WGU Var Array to a fresh blank Onyx customer page. CTRL+SHIFT+1
^+1::
KeyWait, 1
Sleep 100
WinActivate, ahk_id %Onyx1%
Sleep 200
MouseClick, Left, 360, 142 ;Click Customer Power Page
Sleep 200
MouseClick, Left, 1003, 239 ;Click the Onyx "White Plus" icon
Sleep 250
ImageSearch, ONYX_Ind_X1, ONYX_Ind_Y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *100 Onyx_Ind.bmp
Sleep 50
MouseClick, Left, ONYX_Ind_X1+5, ONYX_Ind_Y1+8
Sleep 100
Send {Tab}{Enter}
Sleep 3000
ImageSearch, ONYX_White_Plus_X1, ONYX_White_Plus_Y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *100 Onyx_White_Plus1.bmp
Sleep 50
MouseClick, Left, ONYX_First_Name_X1+35, ONYX_White_Plus_Y1+5 ;Click the Onyx "White Plus" icon inside the secondary search screen to get
inside the blank new individual screen.
Sleep 1000
ImageSearch, ONYX_First_Name_X1, ONYX_First_Name_Y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *100 ONYX_First_Name.bmp
Sleep 50
MouseClick, Left, ONYX_First_Name_X1+80, ONYX_First_Name_Y1+10 ;Click the Onyx First Name Field
Send %WGU_First_Name%
Sleep 100
Send {Tab 2}%WGU_Last_Name%
Sleep 100
Send {Tab}%WGU_Phone_1of3%
Sleep 100
Send ^a^c{Del} ; Copy And Clear Tel# 1of3
ImageSearch, ONYX_New_Phone_X1, ONYX_New_Phone_Y1, 0, 0, A_ScreenWidth, A_ScreenHeight, *100 ONYX_New_Phone.bmp
Sleep 50
MouseClick, Left, ONYX_New_Phone_X1+50, ONYX_New_Phone_Y1+10 ;Click the Onyx Tel# Field
Sleep 100
Send ^V ; Paste part 1 of Tel#
Sleep 100
MouseClick, Left, ONYX_First_Name_X1+80, ONYX_First_Name_Y1+10 ;Click the Onyx First Name Field
Sleep 100
Send {Tab 3}%WGU_Phone_2of3%^a^c{Del} ; Copy And Clear Tel# 2of3
Sleep 250
MouseClick, Left, ONYX_New_Phone_X1+100, ONYX_New_Phone_Y1+10 ;Click the Onyx Tel# Field
Sleep 100
Send ^V ; Paste part 2 of Tel#
Sleep 100
MouseClick, Left, ONYX_First_Name_X1+80, ONYX_First_Name_Y1+10 ;Click the Onyx First Name Field
Sleep 100
Send {Tab 3}%WGU_Phone_3of3%^a^c{Del} ; Copy And Clear Tel# 3of3
Sleep 250
MouseClick, Left, ONYX_New_Phone_X1+120, ONYX_New_Phone_Y1+10 ;Click the Onyx Tel# Field
Sleep 100
Send ^V ; Paste part 3 of Tel#
ReturnTo get the whole thing to be useful it has to get longer, so this is just gonna get worse unless someone knows a solution. Thanx in advance...