I think you are just trying to make a simple function
https://autohotkey.com/docs/Functions.htm. Try this:
Code: Select all
F10::
Loop,
{
Suspend
CopyIDfromExcel()
WinActivate, Google Chrome
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Status
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, {Up 2}
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Search by:
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, ^v
Sleep 3000
Send, {Tab 4}
Sleep 2000
Send, {Enter}
Sleep 3000
Send, ^f
Sleep 1500
SendRaw, Manage
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Enter}
Sleep 5000
CopyIDfromExcel()
}
; Function (I usually put my custom functions at the bottom of my scripts):
CopyIDfromExcel() {
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Right}
Clipboard := ""
send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 1000
}
or you can take the whole chunk to a function like this:
Code: Select all
F10::
Loop,
{
Suspend
CopyIDEntireProcess()
}
; Function
CopyIDEntireProcess() {
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Down}
Sleep 500
Clipboard := ""
Send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 2000
WinActivate, Google Chrome
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Status
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, {Up 2}
Sleep 1000
Send, ^f
Sleep 1000
SendRaw, Search by:
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Tab}
Sleep 1000
Send, ^v
Sleep 3000
Send, {Tab 4}
Sleep 2000
Send, {Enter}
Sleep 3000
Send, ^f
Sleep 1500
SendRaw, Manage
Sleep 1000
Send, {Escape}
Sleep 1000
Send, {Enter}
Sleep 5000
WinActivate, Script Data.xlsx - Excel
Sleep 1000
Send, {Right}
Clipboard := ""
send, ^c
ClipWait
if (Clipboard = "`r`n")
break
Sleep 1000
}
Also, I would highly recommend using COM to automate Excel as opposed to sending keystrokes, it is much faster and more reliable and can run in the background invisibly if needed. I started out trying to automate excel in the way you are doing (and I think a lot of people do) and it was very unreliable and required a lot Sleep and Send commands that aren't very reliable. PM me and I'd be happy to give you more info on automating Excel via COM. You can also do this to automate web scraping, there are tons of tutorials on it, but I'm not that experienced with it yet so you'll have to put in the work yourself
![Why blow the cream? :beer:](./images/smilies/beer.gif)