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 !!!!!!!
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 !!!
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.