Paste data to Excel Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Haan
Posts: 12
Joined: 14 Nov 2020, 19:34

Paste data to Excel

01 Dec 2020, 18:22

Please, I need help with this situation:

I wanna Paste data in Excel's cells. One cell each time I hit the HotKey.

Code: Select all

[::	
	WinActivate QWS3270 EXTRA
	CoordMode, Mouse, Window
	Send {Click 519, 195, down}{click 376, 191, up}
	Sleep 100
	Send ^C
	Sleep 100
	Var1 := clipboard
	Plan1 := ComObjGet("C:\Users\" . A_UserName . "\Desktop\PesquisaRouboRec.xlsx")
	Plan1.Sheets("Plan1").Cells(1, 1).Value := Var1	;---> HERE IS MY PROBLEM
	Plan1.save
	return
Plan1.Sheets("Plan1").Cells(1, 1).Value := Var1 ;---------> HERE IS MY PROBLEM. The selected cell is always A1

I wanna paste the clipboard (wich I called Var1) in bellow cell each time I hit at the " [ " hotkey.
I don't know the syntax to write the Range to indicate to paste at next empty cell at the next Line (same A colum)

Let's say I already have untill A10 with data. So, when I gonna hit " [ ", the clipboard will need to paste at A11. At the next time will be pasted at A12...

I appreciate any help (again)!!!
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: Paste data to Excel  Topic is solved

01 Dec 2020, 20:51

The last non-empty row in a column can be established using this:

Code: Select all

xl := ComObjActive("Excel.application")
lstrw := xl.Range("A" xl.Rows.Count).End(-4162).Row
to the first empty row is lstrw + 1
14.3 & 1.3.7
Haan
Posts: 12
Joined: 14 Nov 2020, 19:34

Re: Paste data to Excel

01 Dec 2020, 21:38

flyingDman wrote:
01 Dec 2020, 20:51
The last non-empty row in a column can be established using this:

Code: Select all

xl := ComObjActive("Excel.application")
lstrw := xl.Range("A" xl.Rows.Count).End(-4162).Row
to the first empty row is lstrw + 1
AMAZING !!!!!!! :wtf:

Here is the Complete code to help whoever needs too.

Code: Select all

#SingleInstance force
#Persistent
#WinActivateForce
#NoEnv

IfExist C:\Users\%A_UserName%\Desktop\PesquisaRouboRec.xlsx
	{
		Excel := ComObjCreate("Excel.Application")
		Excel := ComObjActive("Excel.Application")
		Excel.Workbooks.Open("C:\Users\" . A_UserName . "\Desktop\PesquisaRouboRec.xlsx")
	}
IfNotExist C:\Users\%A_UserName%\Desktop\PesquisaRouboRec.xlsx
	{
		Excel := ComObjCreate("Excel.Application")
		Excel.Workbooks.Add
		Excel.ActiveWorkbook.SaveAs("C:\Users\" . A_UserName . "\Desktop\PesquisaRouboRec.xlsx")
	}

Excel.Visible := 1
return

[::
	WinActivate QWS3270 EXTRA
	CoordMode, Mouse, Window
	Send {Click 519, 195, down}{click 376, 191, up}
	Sleep 100
	Send ^C
	Sleep 100
	Var1 := clipboard
	Plan1 := ComObjGet("C:\Users\" . A_UserName . "\Desktop\PesquisaRouboRec.xlsx")
	lstrw := Excel.Range("A" Excel.Rows.Count).End(-4162).Row
	Plan1.Sheets("Plan1").Range("A" lstrw + 1).Value := Var1
	Plan1.save
	Send {Click 373, 101, down}{click 320, 102, up}
	Sleep 100
	Send ^c
	Sleep 100
	Var2 := clipboard
	Plan1 := ComObjGet("C:\Users\" . A_UserName . "\Desktop\PesquisaRouboRec.xlsx")
	lstrw := Excel.Range("B" Excel.Rows.Count).End(-4162).Row
	Plan1.Sheets("Plan1").Range("B" lstrw + 1).Value := Var2
	Plan1.save
	Send {Click 519, 212, down}{click 375, 208, up}
	Sleep 100
	Send ^c
	Sleep 100
	Var3 := clipboard
	Plan1 := ComObjGet("C:\Users\" . A_UserName . "\Desktop\PesquisaRouboRec.xlsx")
	Plan1.Sheets("Plan1").Range("C" lstrw + 1).Value := Var3
	Plan1.save
	return
Worked perfectly flyingDman
This Lines:
lstrw := Excel.Range("A" Excel.Rows.Count).End(-4162).Row
Plan1.Sheets("Plan1").Range("A" lstrw + 1).Value := Var1
Plan1.save
Are thanks to you !!! :bravo:

For the record. Before your answer, I tried (with awkward result):

Code: Select all

last_cell := Plan1.Sheets("Plan1").Range("A:A").SpecialCells(11).row
	;~ Plan1.Sheets("Plan1").Range("A" last_cell+1).Value := Var2
	;~ Plan1.save
The lines above I took from this forum in another topic. I don't Know what " .SpecialCells(11).row " does. And it was pasting at A2, B3, C3 insted A1, B1, C1

Now is pasting right (I just don't know why it start to paste at A2 B2 C2, and don't use the very first line, A1 B1 C1). However Its perfct to me.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, madensuyu1, peter_ahk and 352 guests