absolute beginner question looping through excel columns

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
faxinger666
Posts: 1
Joined: 14 Mar 2024, 04:25

absolute beginner question looping through excel columns

Post by faxinger666 » 14 Mar 2024, 04:35

hi experts
what i would like to do is:
Macro creator to go through each cell in one column in excel, copy the content of the cell and paste it in another program that is already open.
Do this loop till the end of the column in excel is reached.

For example:
Excel: Cell B2, content is "VALUE1 xyz"
copy "VALUE1 xyz" to another already program "ANYPROG" and paste it there on specific location, click ok button in "ANYPROG"
go to CELL B3, content is "VALUEB 0123"
copy "VALUEB 0123" to another already program "ANYPROG" and paste it there on specific location, click ok button in "ANYPROG"

and so on till the end of column B

Is this possible?
If yes, how can this be done?

Cheers

User avatar
WarlordAkamu67
Posts: 232
Joined: 21 Mar 2023, 06:52

Re: absolute beginner question looping through excel columns

Post by WarlordAkamu67 » 14 Mar 2024, 05:30

Hello! I am unable to contribute much as I do not have the time to test stuff. What you are asking for sounds feasible.

You can search through other posts for idea as to what the code would look like, look for topics that are marked as answered. This post has some code to look at as well as links to other valuable resources about using excel.

User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: absolute beginner question looping through excel columns

Post by flyingDman » 14 Mar 2024, 12:48

Interfacing with Excel is through COM (https://en.wikipedia.org/wiki/Component_Object_Model). Tutorials about using COM with AHK exist and some are listed here viewtopic.php?f=82&t=126973&hilit=excel#p561904. But honestly there is no tutorial or manual encompassing everything there is to know about COM.

The method you describe - i.e. going back and forth between your Anyprog and Excel - is not efficient and would be very slow. Since AHK allows you to read the contents of cells in "the background", the focus can stay on Anyprog while cells are read without having to activate Excel (i.e. Excel needs to be running but not in the foreground).
As an example, start Excel with data as shown, launch the script, then load the following html file and put the cursor in the first box. Now press F12. The html form should populate with the Excel data.

Code: Select all

xl := ComObjActive("excel.application")
f12::
	{
	for c in xl.activesheet.usedrange.columns(1).cells
		send c.text "{tab}"
	}
HTML file
image.png
image.png (8.96 KiB) Viewed 111 times
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v2)”