Created
June 14, 2020 14:31
-
-
Save JoeGlines/ba64917632365613fd492ec86b284da5 to your computer and use it in GitHub Desktop.
just code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LastMon:=GetLastMonday() | |
;********************Start script- get location*********************************** | |
Ref:=GetXLInfo() ;Gets called first to get where you are In Excel and pull the Location | |
SearchAS400(LastMon,Ref.Location_Digits,Ref.ProductID) ;Get the data from AS400 | |
PushToXL(Ref) ;Shove data back into Excel | |
return | |
;********************Get where you are in Excel to use later*********************************** | |
GetXLInfo(){ | |
XL:=XL_Handle(1) | |
XLData:=[] ;create Arra to hold the variou data points | |
XLData.ProductID :=XL.range(XL.selection.address(0,0)).offset(0,-2).text | |
XLData.Active_Row :=XL.Selection.Row | |
XLData.Active_Col :=XL.Selection.Column | |
XLData.Active_Cell_Value :=XL.Selection.Value | |
;~ MsgBox % XLData.Product_ID :=XL.Range(Xl.selection).Offset(-2,0).Value | |
XLData.Location_Digits:=SubStr(XLData.Active_Cell_Value,3) ;Just get the 3rd to the ending charachter | |
return XLData | |
} | |
;********************Do the search*********************************** | |
SearchAS400(LastMon,Location,ProdID){ | |
Clipboard:=LastMon ;"060620" | |
WinActivate, ahk_exe acslaunch_win-64.exe | |
Sleep, 100 | |
Send,^v ; paste date | |
sleep, 100 | |
SendInput, `t ;tab to next one | |
sleep, 100 | |
Clipboard:=Location ;"0138" ;location | |
sleep, 100 | |
Send,^v ; | |
sleep, 600 | |
Clipboard:= ProdID ;Product ID | |
sleep, 600 | |
SendInput, `t ;do we need this? | |
Send,^v ;Product ID | |
sleep, 100 | |
Send {Enter} ;Complete the search | |
sleep, 100 | |
Send ^c ;Copy the screen | |
Return Clipboard | |
} | |
;****************Loop over results and push back to Excel*************************************** | |
PushToXL(Info){ | |
XL:=XL_Handle(1) | |
FileRead,data,C:\AHK Studio\Projects\example.txt | |
;*********Use For loop over Var going line by line********************* | |
for i, row in Loopobj:=StrSplit(data,"`n","`r`n") { ;Parse Var on each new line | |
If (SubStr(Row,1,4)="Opt ") | |
Start=1 | |
if (Start=1){ | |
if (SubStr(Row,1,4)!="Opt "){ ;here on will be locations | |
Ent:=SubStr(Row,1,4)+0 ;adding zero tells ahk to store it as a number | |
if (Ent){ | |
nextCol++ | |
Offset:=SubStr(row,45,1) | |
Ent:=Format("{:04}", Ent) ;0003 ;string will be at least 4 digits long | |
XL.Range(XL_Col_To_Char(Info.Active_Col+nextCol) Info.Active_Row).NumberFormat := "@" ;change to string | |
XL.Range(XL_Col_To_Char(Info.Active_Col+nextCol) Info.Active_Row).Value:=Ent | |
if (Offset>0){ | |
XL_Insert_Comment(XL,XL_Col_To_Char(Info.Active_Col+nextCol)Info.Active_Row," " Offset,0,12,,5) | |
XL.Range(XL_Col_To_Char(Info.Active_Col+nextCol) Info.Active_Row).Interior.ColorIndex :=6 | |
} } | |
Ent:="", Offset:="" | |
} | |
} | |
} | |
} | |
GetLastMonday(){ | |
WDay:=4 ;Sunday is 1, Monday is 2....etc | |
Sub:=8-WDay | |
Now:=A_Now | |
Now+=-Sub,dd | |
FormatTime,Date,%Now%,MMddyy | |
return Date | |
} | |
XL_Handle(Sel){ | |
ControlGet, hwnd, hwnd, , Excel71, ahk_class XLMAIN ;identify the hwnd for Excel | |
Obj:=ObjectFromWindow(hwnd,-16) | |
return (Sel=1?Obj.Application:Sel=2?Obj.Parent:Sel=3?Obj.ActiveSheet:"") | |
} | |
;***borrowd & tweaked from Acc.ahk Standard Library*** by Sean Updated by jethrow***************** | |
ObjectFromWindow(hWnd, idObject = -4){ | |
if(h:=DllCall("LoadLibrary","Str","oleacc","Ptr")) | |
If DllCall("oleacc\AccessibleObjectFromWindow","Ptr",hWnd,"UInt",idObject&=0xFFFFFFFF,"Ptr",-VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0 | |
Return ComObjEnwrap(9,pacc,1) | |
} | |
;***********************Numeric Column to string********************************. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment