COM command to sort unknown table size in excel

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jimi_hendrix2017
Posts: 16
Joined: 04 Jul 2017, 19:49

COM command to sort unknown table size in excel

21 Jul 2017, 23:45

I have a table WITH a header row, which i would like to sort by ascending order based on the 1st column. The table can be of varying length but should be of fixed width / columns. I found this but it doesnt address my header and order criteria:

Xl := ComObjActive("Excel.Application")
xl.cells.sort(xl.columns(1), 1)
User avatar
jmeneses
Posts: 524
Joined: 28 Oct 2014, 11:09
Location: Catalan Republic

Re: COM command to sort unknown table size in excel

23 Jul 2017, 13:16

Hi jimi_hendrix2017 , try this

Code: Select all

#SingleInstance force
#Persistent

xlByColumns  := 2
xlPrevious   := 2        
	
xlAscending  := 1   
xlDescending := 2
xlHeaderYes  := 1 ;Ignore Header
Return

#If WinActive("ahk_exe EXCEL.exe")     
F1::                             
oExcel := ComObjActive("Excel.Application")	        
oSheet := oExcel.Worksheets(1)
oSheet.Select
oRange := "A1:" RegExReplace(oExcel.Sheets(1).Cells.Find("*", , , , xlByColumns, xlPrevious).Address,"\$")
oSheet.Range(oRange).Cells.Sort(oSheet.Columns(1), xlAscending , ComObjMissing(), , xlHeaderYes )   
oSheet:=""                                    
oExcel:=""
Msgbox DONE!!
Return
Donec Perficiam
jimi_hendrix2017
Posts: 16
Joined: 04 Jul 2017, 19:49

Re: COM command to sort unknown table size in excel

17 Aug 2017, 20:29

@jmeneses Wow, I didnt even see this come in. Ironically I was seraching for the same thing and our old post came up!!. Unfortunately, its not quite working. It just blows right through and doesnt do anything, select the range or sort. Thoughts?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, ArkuS, mikeyww, Nerafius, RandomBoy, sofista and 127 guests