Send keystrokes based of Excel data

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jc0r
Posts: 29
Joined: 27 Nov 2015, 07:09

Send keystrokes based of Excel data

04 Dec 2021, 07:43

Hi all,

I seem to be going around in circles and wondered if anyone could help.

I am trying to send keystrokes to an application when values in an Excel spreadsheet are true.

For example:

Image

The script will be on a loop every 30 seconds, and if a value in column B = TRUE, i then want to activate my app and enter the keystrokes based of columns A and C.

So using the above example, the following would be sent

Code: Select all

Send, 1 {ENTER} 78
Send, 4 {ENTER} 17
Any help would be appreciated.

Many thanks
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Send keystrokes based of Excel data

04 Dec 2021, 08:11

It is possible to access excel via COM, but I have not done it yet, as I use Openoffice. There must be threads about this in the forum.

Maybe an easier way would be to export the excel sheet in csv format and read the exported file.

With openoffice, when I select an area of the spreadsheet and copy it to the clipboard, in ahk the variable clipboard contains the data in tab-delimited format. Maybe something similar is possible with excel.
Last edited by braunbaer on 04 Dec 2021, 08:26, edited 1 time in total.
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Send keystrokes based of Excel data

04 Dec 2021, 08:15

Code: Select all

#Persistent
XL := ComObjActive("Excel.application"), used := XL.ActiveSheet.UsedRange
SetTimer, Check, 30000
Check:
Loop, % used.Rows.Count {
 row := used.Rows(A_Index)
 If (row.Cells(2).Text != "TRUE")
  Continue
 WinActivate, ahk_exe notepad.exe
 Send, % row.Cells(1).Text "`n" row.Cells(3).Text
}
Return
jc0r
Posts: 29
Joined: 27 Nov 2015, 07:09

Re: Send keystrokes based of Excel data

04 Dec 2021, 08:20

Thanyou so much Mikey
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Send keystrokes based of Excel data

04 Dec 2021, 11:48

Rather than using a loop, you can check on whether any of the cells is True using:

Code: Select all

xl := ComObjActive("excel.application")
if (xl.worksheetfunction.countif(xl.range("b:b"),"True"))
	msgbox Hello
14.3 & 1.3.7

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, sharonhuston and 224 guests