End an excel sheet

Get help with using AutoHotkey and its commands and hotkeys
sam456
Posts: 2
Joined: 10 Feb 2020, 12:27

End an excel sheet

10 Feb 2020, 12:32

Hey guys!
I created a script for running an excel file, but I want it to end by itself when it gets to a blank cell. Here is what I am trying to do but it won't work. Please help!

Rate :=
Clipboard :=
Sleep, 500
Send, {Control Down}{c}{Control Up}
Sleep, 700
If Clipboard =
{
Goto, END
}

End:
ExitApp
Return
fenchai
Posts: 236
Joined: 28 Mar 2016, 07:57

Re: End an excel sheet

10 Feb 2020, 15:10

Instead of using classic send keys, use Excel COM instead, here https://autohotkey.com/board/topic/69033-basic-ahk-l-com-tutorial-for-excel/
sam456
Posts: 2
Joined: 10 Feb 2020, 12:27

Re: End an excel sheet

20 Feb 2020, 17:34

Hello Fenchai!

I am using an already created excel sheet, I just want to come to the last cell and make the script stop running.
User avatar
flyingDman
Posts: 745
Joined: 29 Sep 2013, 19:01

Re: End an excel sheet

20 Feb 2020, 19:04

I agree with @Fenchai . Whether you are creating a new spreadsheet or working on an existing one, COM is a significantly better way to go compared to simulated keystrokes.
Here is some code to determine whether the active cell is the cell before the first empty cell in the column or whether the active cell is the last non-empty cell in column (two different things...). I assume you are working top down in column C (rather than left to right).

Code: Select all

Xl := ComObjActive("Excel.Application") 				            			;creates a handle to your Application object

#\::
msgbox % xl.Range("C" xl.Rows.Count).End(-4162).address
if (xl.activecell.address = xl.Range("C" xl.Rows.Count).End(-4162).address) 	;last non-empty cell in col C
	msgbox End 
return

#]::
msgbox % xl.range("C1").end(-4121).address
if (xl.activecell.address = xl.range("C1").end(-4121).address)					;cell just above the first empty cell in col C
	msgbox End 
return

Return to “Ask For Help”

Who is online

Users browsing this forum: barbudo2005, Bing [Bot], boiler, burque505, Getfree, Google [Bot], kdservices, TAC109, WeThotUWasAToad and 154 guests