Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Last active December 15, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TLMcode/5298625 to your computer and use it in GitHub Desktop.
Save TLMcode/5298625 to your computer and use it in GitHub Desktop.
CreateExcelLists() Function to separate value types into 2 lists Strength and Units. Original query: http://ahk4.me/10xyV4j
WorkBook := A_ScriptDir "\book1.xls" ; change this to your workbook location
CreateExcelLists(WorkBook,"A","B",StrengthList,UnitList,"Sheet1")
; optional display
Run Notepad,,, nPid
WinWait, % "ahk_pid " nPid
ControlSetText, Edit1, % "StrengthList:`r`n" StrengthList ; << Strength stored here
. "`r`n" "UnitList:`r`n" UnitList ; << Units stored here
, % "ahk_pid " nPid
; end optional display
;##############################################################
CreateExcelLists(_wb,_c1,_c2,ByRef _sl,ByRef _ul,_st=1,_vs=0) {
ExObj:=ComObjCreate("Excel.Application"),ExObj.visible:=_vs
ExObj.Workbooks.Open(_wb)
While (_Col1:=ExObj.Worksheets(_st).Range(_c1 . A_Index).Value) {
If (_Col2:=ExObj.Worksheets(_st).Range(_c2 . A_Index).Value)~="\B`%\B"
_sl .= Floor(_Col1) " " _Col2 "`r`n"
Else
_ul .= Floor(_Col1) " " _Col2 "`r`n"
} ExObj.Quit
}
;##############################################################
; CreateExcelLists() Usage
; _wb ; workbook name
; _c1 ; 1st Column with number values
; _c2 ; 2nd Column with Unit/Strength values
; _sl ; StrengthList storage variable
; _ul ; UnitList storage variable
; _st=1 ; Sheet to read (Optional, Default: Sheet1)
; _vs=0 ; Object visiblility (Optional, Default: Hidden), for debugging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment