Sign in to follow this  
Followers 0
Paul

Reading CellValue and continue a loop

7 posts in this topic

Hello!!

I have a small problem writing this.

#Include <Excel.au3>

$sFilePath1 = "C:\Users\admin\Desktop\NovOrders.xls"

$oExcel = _ExcelBookOpen($sFilePath1)

$i = 1 (I want to start with the first A1)

Do

$sCellValue = _ExcelReadCell($oExcel, 1, $i)

(Here I execute a window)

Send("{TAB 1}")

Send($sCellValue)

Send("{TAB 2}")

Send("{ENTER}")

Until $sCellValue = 0 (Repeat from Do Until the CellValue=0)

I'm doing something wrong. Any clues??

Thanks!

Share this post


Link to post
Share on other sites



This is one example of the "loop" you wanted

****** NOT TESTED

#include <Excel.au3>
$sFilePath1 = "C:\Users\admin\Desktop\NovOrders.xls"

$oExcel = _ExcelBookOpen($sFilePath1)

Local $i = 0 ;(I want to start with the first A1)
Do
    $i += 1
    $sCellValue = _ExcelReadCell($oExcel, 1, $i)
    If @error Then ExitLoop
    
    ;(Here I execute a window)
    Run("notepad.exe")
    WinWaitActive("")
    
    Send("{TAB 1}")
    Send($sCellValue)
    Send("{TAB 2}")
    Send("{ENTER}")

Until $sCellValue = 0 ;(Repeat from Do Until the CellValue=0)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Thanks!! I tried it out, I seem to be missing something still since it will just stop after the first ReadCell. It won't keep doing it with A2.

Any ideas??

thanks a lot!

This is one example of the "loop" you wanted

****** NOT TESTED

#include <Excel.au3>
$sFilePath1 = "C:\Users\admin\Desktop\NovOrders.xls"

$oExcel = _ExcelBookOpen($sFilePath1)

Local $i = 0 ;(I want to start with the first A1)
Do
    $i += 1
    $sCellValue = _ExcelReadCell($oExcel, 1, $i)
    If @error Then ExitLoop
    
    ;(Here I execute a window)
    Run("notepad.exe")
    WinWaitActive("")
    
    Send("{TAB 1}")
    Send($sCellValue)
    Send("{TAB 2}")
    Send("{ENTER}")

Until $sCellValue = 0 ;(Repeat from Do Until the CellValue=0)

8)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Just tested this example for cells A1-A5 and works good:

#include <Excel.au3>

$oExcel = _ExcelBookOpen($sFilePath1)
$sCellsValue = _ExcelReadArray($oExcel,1,1,5,1,1)
_ExcelBookClose($oExcel,0,0)

Run("notepad.exe")
WinWaitActive("")
For $INDEX = 1 To $sCellsValue[0]
    Send("{TAB 1}")
    Send($sCellsValue[$INDEX])
    Send("{TAB 2}")
    Send("{ENTER}")
Next
MsgBox(0,"","FINISH")

And you don't need any loop.

Or this example, writing results directly in the file.

#include <Excel.au3>
#include <File.au3>
$sFilePath1 = @ScriptDir & "\Test.xls"
$oExcel = _ExcelBookOpen($sFilePath1,0)
$sCellsValue = _ExcelReadArray($oExcel,1,1,5,1,1)
_ExcelBookClose($oExcel,0,0)
_FileWriteFromArray(@ScriptDir & "\Result.txt",$sCellsValue,1)
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Thanks! But I have to do it one by one.

Read A1

Put in a form in firefox

Read A2

Put in a new form in firefox

so and on until A1=0

Just tested this example for cells A1-A5 and works good:

#include <Excel.au3>

$oExcel = _ExcelBookOpen($sFilePath1)
$sCellsValue = _ExcelReadArray($oExcel,1,1,5,1,1)
_ExcelBookClose($oExcel,0,0)

Run("notepad.exe")
WinWaitActive("")
For $INDEX = 1 To $sCellsValue[0]
    Send("{TAB 1}")
    Send($sCellsValue[$INDEX])
    Send("{TAB 2}")
    Send("{ENTER}")
Next
MsgBox(0,"","FINISH")

And you don't need any loop.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks! But I have to do it one by one.

Read A1

Put in a form in firefox

Read A2

Put in a new form in firefox

so and on until A1=0

But you can have it one by one, only the results is in an array; It is exactly as you read the xls file.

For $INDEX = 1 To $sCellsValue[0]
    MsgBox(0,"A" & $INDEX,$sCellsValue[$INDEX])
Next

If is more easy for you:

#include <Excel.au3>

$CellNums = InputBox("Number of cells","Type here the number of cells",5)
$oExcel = _ExcelBookOpen($sFilePath1,0)

For $INDEX = 1 To $CellNums
    $sCellValue = _ExcelReadCell($oExcel,$INDEX)
    MsgBox(0,"Cell: A" & $INDEX,$sCellValue)
    #cs
        (Here I execute a window)
        Send("{TAB 1}")
        Send($sCellValue)
        Send("{TAB 2}")
        Send("{ENTER}")
    #ce
    Next
_ExcelBookClose($oExcel,0,0)
Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

Thanks!!

Works perfectly!

I owe you.

But you can have it one by one, only the results is in an array; It is exactly as you read the xls file.

For $INDEX = 1 To $sCellsValue[0]
    MsgBox(0,"A" & $INDEX,$sCellsValue[$INDEX])
Next

If is more easy for you:

#include <Excel.au3>

$CellNums = InputBox("Number of cells","Type here the number of cells",5)
$oExcel = _ExcelBookOpen($sFilePath1,0)

For $INDEX = 1 To $CellNums
    $sCellValue = _ExcelReadCell($oExcel,$INDEX)
    MsgBox(0,"Cell: A" & $INDEX,$sCellValue)
    #cs
        (Here I execute a window)
        Send("{TAB 1}")
        Send($sCellValue)
        Send("{TAB 2}")
        Send("{ENTER}")
    #ce
    Next
_ExcelBookClose($oExcel,0,0)

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0