Excell Cell offset

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Excell Cell offset

10 Oct 2018, 08:11

In a MS Excel project this works for me.

XL := ComObjActive("Excel.Application")
Cell_value = % XL.ActiveCell.value
XL.ActiveCell.Offset(1,-3).Activate

I want to apply this after I tab from any cell I might be in in column “G”. I have a hot key that I have tied to the “Tab” key and I’m thinking I need to check the row each time I use this hotkey. If not in “G” then “Tab” and If in “G” then the above offset. Is this a OK way to do this and if so how would I proceed here? Thanks
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Excell Cell offset

10 Oct 2018, 13:31

Code: Select all

$Tab::
	xlApp := ComObjActive("Excel.Application")
	if (xlApp.ActiveCell.Column = 7)
		xlApp.ActiveCell.Offset(1,-3).Activate
	else
		Send {Tab}
return
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Re: Excell Cell offset

10 Oct 2018, 23:46

Hello, Thank you for the help here. Your script ran fine when I tab through the cells without entering data but when I add data and then try tabbing to the next cell I get a error message. "Error 0X8001000 - Call was rejected by callee. Specifically: ActiveCell. Then there is a arrow pointing to this line ---> if (xlApp.ActiveCell.Column = 7).
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Excell Cell offset

11 Oct 2018, 12:53

codude wrote:Hello, Thank you for the help here. Your script ran fine when I tab through the cells without entering data but when I add data and then try tabbing to the next cell I get a error message. "Error 0X8001000 - Call was rejected by callee. Specifically: ActiveCell. Then there is a arrow pointing to this line ---> if (xlApp.ActiveCell.Column = 7).
You can't access the ActiveCell while the cell is in edit mode (when typing text with the vertical bar cursor showing). Because while in edit mode the cell has no defined value or lots of other properties so Excel rejects access attempts for that cell at that moment.

The simplist way to avoid this is to just always exit edit mode when the script fires.

Code: Select all

$Tab::
	Send ^{Enter}
	xlApp := ComObjActive("Excel.Application")
	if (xlApp.ActiveCell.Column = 7)
		xlApp.ActiveCell.Offset(1,-3).Activate
	else
		Send {Tab}
return
Control+Enter accepts edits, exits edit mode, and stays in the same cell. You could add some checks to make sure you are in edit mode before sending the Control+Enter but it rare does anything bad when sent even when not in edit mode.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
codude
Posts: 128
Joined: 12 Nov 2015, 05:33

Re: Excell Cell offset

11 Oct 2018, 22:37

Perfect! Thanks for taking the time to help me out here.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: CuriousDad, rc76 and 228 guests