Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;==================================================
- ;FILE MUST BE OPENED BEFORE RUNNING SCRIPT
- ;==================================================
- GLOBAL xlup = -4162
- GLOBAL xldown = -4121
- GLOBAL xlLeft = -4159
- GLOBAL xlRight = -4161
- ;This is the function i use for grabbing open/active excel workbooks - you dont need to use this, but its what i prefer :)
- xl := XL_Check()
- ;Get the length of headers to loop through - im assuming headers start at A1 - and are always in Row 1
- HeaderColumns := xl.sheets("sheet1").range("A1").end(xlright)["column"]
- Loop % HeaderColumns
- {
- ;Convert Index number to letter so we can loop easily through the columns(1=A, 2=B, 3=C, etc....)
- Col := ConverttoLetter(A_Index) ;Helper Function Below
- Header := xl.sheets("sheet1").range(Col "1").value
- ;Get the length of data within that column - we can now loop through it and create our Gui
- Rows := xl.sheets("sheet1").range(col "2").end(xldown)["row"]
- Gui, Add, text, w100 x+10 ym, % Header
- Loop % Rows - 1
- {
- RowContent := xl.sheets("sheet1").range(Col A_Index + 1).value
- Gui, add, edit,,% RowContent
- }
- }
- gui,show,autosize
- return
- ESC::
- guiclose:
- exitapp
- ConvertToLetter(n)
- {
- while (n != 0) {
- t := Mod((n - 1), 26)
- n := (n - t) // 26
- l := chr(65 + t) l
- }
- return l
- }
- ConvertToNumbers(l)
- {
- colnum:=0
- Loop % strlen(l)
- colnum := (colnum*26) + (asc(SubStr(l,A_Index,1))-64)
- return colnum+0
- }
- XL_Check(WinTitle:="ahk_class XLMAIN", Excel7#:=1) {
- static h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
- WinGetClass, WinClass, %WinTitle%
- if !(WinClass == "XLMAIN")
- return "Window class mismatch."
- ControlGet, hwnd, hwnd,, Excel7%Excel7#%, %WinTitle%
- if (ErrorLevel)
- return "Error accessing the control hWnd."
- VarSetCapacity(IID_IDispatch, 16)
- NumPut(0x46000000000000C0, NumPut(0x0000000000020400, IID_IDispatch, "Int64"), "Int64")
- if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", -16, "Ptr", &IID_IDispatch, "Ptr*", pacc) != 0
- return "Error calling AccessibleObjectFromWindow."
- window := ComObject(9, pacc, 1)
- if ComObjType(window) != 9
- return "Error wrapping the window object."
- Loop
- try return window.application
- catch e
- if SubStr(e.message, 1, 10) = "0x80010001"
- ControlSend, Excel7%Excel7#%, {Esc}, %WinTitle%
- else
- return "Error accessing the application object."
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement