ToRoM23 Posted February 9, 2019 Posted February 9, 2019 Hi everybody, I'm getting some problem with my code. As the title of the topic, I have to get a variable column from excel to an array and then paste the contents of the array to another program (like notepad) one by one. Here is the function. #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <Excel.au3> ;OPEN EXCEL FILE Local $oExcel = _Excel_Open() Local $Fo1 = "C:\Users\User\Desktop\Prodotti.xlsx" Local $oWorkbook = _Excel_BookOpen($oExcel, $Fo1) ;READ THE COLUMN FORM THE ACTIVE SHEET $EAN = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"), 1) ; PASTE VALUE FROM ARRAY TO NOTEPAD For $iEAN = 0 to UBound($EAN) - 1 _ArrayToClip ($EAN[$iEAN],"", Default) WinActivate ("[CLASS:Notepad]", "") Send ("^v") Send ("{enter}") Next However it don't return nothing in notepad. Thanks to those who can help me PS: I'm Italian... sorry for my english if I wrote something wrong...
Subz Posted February 9, 2019 Posted February 9, 2019 (edited) Try ClipPut, _ArrayToClip is for capturing an array to clipboard, it would be better if you used something like: Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) For $i = 0 To UBound($aArray) - 1 ControlSend($hWnd, "", "Edit1", $aArray[$i] & @LF) Next Edited February 9, 2019 by Subz
ToRoM23 Posted February 9, 2019 Author Posted February 9, 2019 I tried this... but still doesn't work.. of course I'm doing somenthing wrong .... ; PASTE VALUE FROM ARRAY TO NOTEPAD For $iEAN = 0 to UBound($EAN) - 1 ClipGet () WinActivate ("[CLASS:Notepad]", "") Send ("^v") Send ("{enter}") Next
ToRoM23 Posted February 9, 2019 Author Posted February 9, 2019 Sorry, I didn't see your code. Now I'll try.
Subz Posted February 9, 2019 Posted February 9, 2019 (edited) Sorry I meant ClipPut($EAN[$iEAN]) however the method I posted above is a better solution as it doesn't revolve send function ControlSend is more targeted solution, whereas send can have some unpredictable results and should only be used as a last resort. Edited February 9, 2019 by Subz
ToRoM23 Posted February 9, 2019 Author Posted February 9, 2019 45 minutes ago, Subz said: Try ClipPut, _ArrayToClip is for capturing an array to clipboard, it would be better if you used something like: Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) For $i = 0 To UBound($aArray) - 1 ControlSend($hWnd, "", "Edit1", $aArray[$i] & @LF) Next This works perfectly!!! Thank you very much!!!!! Here is the entire code edited. #include <Array.au3> #include <File.au3> #include <MsgBoxConstants.au3> #include <Excel.au3> ;OPEN EXCEL FILE Local $oExcel = _Excel_Open() Local $Fo1 = "C:\Users\User\Desktop\Prodotti.xlsx" Local $oWorkbook = _Excel_BookOpen($oExcel, $Fo1) Local $hWnd = WinWait("[CLASS:Notepad]", "", 10) ;READ THE COLUMN FORM THE ACTIVE SHEET $EAN = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"), 1) ; PASTE VALUE FROM ARRAY TO NOTEPAD For $iEAN = 0 to UBound($EAN) - 1 ControlSend($hWnd, "", "Edit1", $EAN[$iEAN] & @LF) Next Thanks a lot!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now