Copy Paste from Excel into Another Program

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mehrez1989
Posts: 5
Joined: 25 Oct 2019, 18:54

Copy Paste from Excel into Another Program

10 Nov 2019, 22:09

Hi Everyone

I am new in AHK scripting, I have a task of which I need to copy paste a series of cells in a column in a specific excel file one by one through hitting a hotkey every time and it is pasting it into another program and when hitting again the hotkey it goes to the next cell copying it and pasting to the other program etc.
I have used the Winactivate function to limit the process only between the excel file and the the running program.

Recently, I have experienced that it is just doing copy paste for the first time when hitting the hotkey, But when hitting the hotkey again to copy the next cell, It doesn't work
and still remains in the program window

How can I solve this problem ?

Thanks in advance for your kind help

The following is my script that I have written:

Code: Select all

!e::
WinActivate, Test1 - Excel ahk_class XLMAIN
send, {Down}
send, ^c
WinActivate, Program Server 1 ahk_class Program
Click, 229, 228, 2
sleep,300
send, ^v
send, {enter}
clipboard =
sleep,100
return

!b::
WinActivate, Test1 - Excel ahk_class XLMAIN
send, {Up}
send, ^c
WinActivate, Program Server 1 ahk_class Program
Click, 229, 228, 2
sleep,300
send, ^v
send, {enter}
clipboard =
sleep,100
return

!x::ExitApp
[Mod edit: [code][/code] tags added]
User avatar
flyingDman
Posts: 2821
Joined: 29 Sep 2013, 19:01

Re: Copy Paste from Excel into Another Program

10 Nov 2019, 23:45

First, I would recommend to do a search on the forum. If you search on Copy Excel, I am getting close to 1000 results. This first few results should lead you to use COM to do this.
The following uses that but with a little twist. It shows in a tooltip next to the mouse pointer a list of the next 10 values to be pasted (one by one). Ctrl Lbutton pastes the next value in at the insertion point. The tooltip list is refreshed each time you press Ctrl Lbutton. Excel file needs to be open, but can be in the background.

Code: Select all

Xl := ComObjActive("Excel.Application")
arr:=[]
For c In xl.activesheet.usedrange.cells
	arr.push(c.text)
gosub rfrsh
return

^LButton::
Click
clipboard := Arr.RemoveAt(1)
send ^v
list10 := ""

rfrsh:
for x,y in arr
	{
	list10 .= y "`n"
	if (x = 10)
		break
	}
SetTimer, tt, 100
return

tt:
MouseGetPos, oX,oY
Tooltip, %list10%, oX + 25,  oY + 25
return
14.3 & 1.3.7

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hitman, sachalamp and 422 guests