Greetings, Gurus.
I'm certain this has been done, but hours of searching didn't turn up the advice I needed.
I have a simple script that utilizes several hotkeys to copy values from an Excel file to another application. The hotkeys have to jump back and forth several times. I can use the name of the other application that we are copying to, because it's always the same, but can't use the name of the Excel file because it is always different.
In a nutshell.., how do you code AHK to use a particular Excel file, (perhaps selected via dropdown, but not necessarily), and continue to use it for all hotkeys in the script?
Here's what I've tried, and it sort of works, but the problem is I'm trying to train several users to use the script, (several times a day), and this only works if they make certain Excel is the active window when they press the hotkey:
Code:
^Numpad1:: ;;Copy active cell from Excel and paste into ADS.
xlid:=WinExist("A")
GroupAdd, XLCOPY, ahk_id %xlid%
WinWait, ahk_group XLCOPY,
IfWinNotActive, ahk_group XLCOPY, , WinActivate, ahk_group XLCOPY,
WinWaitActive, ahk_group XLCOPY,
Send, ^c
WinWait, ADS-KEYSTONE.sbc - SBClient,
IfWinNotActive, ADS-KEYSTONE.sbc - SBClient, , WinActivate, ADS-KEYSTONE.sbc - SBClient,
WinWaitActive, ADS-KEYSTONE.sbc - SBClient,
Send, {F9}
Sleep, 200
Send, {ALTDOWN}{SHIFTDOWN}{INS}{SHIFTUP}{ALTUP}
Exit
^Numpad2:: ;;Go back to Excel, down to next part, then repeat step 1.
WinWait, ahk_group XLCOPY,
IfWinNotActive, ahk_group XLCOPY, , WinActivate, ahk_group XLCOPY,
WinWaitActive, ahk_group XLCOPY,
Send, {DOWN}
Exit
There are other hotkeys involved, that's just a small sample. Another problem is that none of the other keys work unless hotkey ^Numpad1 was pressed first, with the correct Excel window active, because thats the script that activates the excel file. After the user has used the hotkeys several times to copy and paste values into ADS, they will close the excle workbook and open another one with a different name, (same format), and do it all over again. Ideally, AHK would recognize when one file has closed and a new one has opened and prompt the user for the name of the new file, so they can begin working from the new file.
So, I'm sure some experienced users will know, what's the best way to work with multiple excel files having various names?
Thanks in advance for any help you can offer.