Jump to content

Recommended Posts

Posted

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 :D

 

PS: I'm Italian... sorry for my english if I wrote something wrong...  :sweating:

Posted (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 by Subz
Posted
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!

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...