Jump to content
Sign in to follow this  
SkysLastChance

[Newbie] Help with _ExcelReadSheetToArray

Recommended Posts

SkysLastChance

I was wondering if it is possible to make a input box that could change the number of rows? 

So instead of $aArray= _ExcelReadSheetToArray($oExcel,2,1,10,3,True)

I was wondering If I could have a input box where I can change the number of row to a variable number each time I run the bot? 

Because sometimes I might have 10 row other times I might have 250... 

Sorry, If this is not the right place for this post. This is the first time I have posted 

Any help would be awesome. Thanks :)


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

Use function InputBox to get the number from the user and assign it to a variable. Then pass the variable to _ExcelReadSheetToArray.

Make sure to use function "Number" to convert the string returned by InputBox to a number.

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
SkysLastChance

Awesome, Thank you for the quick response! 

This is what I did

$number = inputbox( "Sky Bot", "How many entires?")

_ExcelReadSheetToArray($oExcel,2,1,$number,3,True)


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

Out of curiosity: Can you explain what your "Sky bot" is?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
SkysLastChance

#include <File.au3>
#include <Excel.au3>
#include <Word.au3>
#include <Array.Au3>
#include <Clipboard.au3>

$number = inputbox( "Sky Bot", "How many entires?")


HotKeySet("{ESC}", "Terminate")
Func Terminate()
    Exit 0
EndFunc
Opt("SendKeyDelay", 80)
Dim $oExcel, $sExcelFile, $ms
Dim $fExcelVisible = 1 ;Change this to 0 for Production
While ProcessExists("EXCEL.EXE")
$ms = MsgBox(5,"","Process error.  You have an Excel sheet open.  You must close it in order to let this program work.  Please close it now.") ;Retry=4 and Cancel=2
    If $ms=2 Then Exit
Sleep(250)
WEnd
$sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsx)") ;Changed $oExcel to $sExcelFile
If FileExists($sExcelFile) Then

    $oExcel = _ExcelBookOpen($sExcelFile,$fExcelVisible, False);this will open the chosen xls file.
If IsObj($oExcel) Then ConsoleWrite("Excel book " & $sExcelFile & " has been opened." & @CRLF)
Else
$oExcel = _ExcelBookNew($fExcelVisible);this is here to create the xls file if it does not exist.


EndIf
$aArray= _ExcelReadSheetToArray($oExcel,2,1,$number,3,True) ; $iStartRow = 1, $iStartColumn = 1, $iRowCnt = 10, $iColCnt = 3, $iColShift = True as excel
$rows = 1
Opt("WinTitleMatchMode", 1)
Local $loop = 0
Run("notepad.exe")

Do
For $i =  1 to $aArray[0][0]  ; if you change 1 it will start reading from that.
$sR1 = $aArray[$i][0] ; Entry Number
$sR2 = $aArray[$i][1] ; Weight
$sR3 = $aArray[$i][2] ; Value

WinWaitActive("Untitled - Notepad")
send($sR1)
send("{ENTER}")
send($sR2)
send("{ENTER}")
send($sR3)
send("{ENTER}")
Next

    $loop = $loop + 1
Until $loop = $rows


_ExcelBookClose($oExcel) ; close excel
ProcessClose("Excel.exe") ; close excel
MsgBox(0,"Sky Bot ","Total Number of Entries" &": "& $i - 1) ;ProcessClose("notepad.exe") ; close notepad ;send("!n")


Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
SkysLastChance

It is not done yet. I am using notepad as a testing program, until I get it working how I want. I just basically need it to move information from excel into my program to store data.

side question: I am probably going to look this up tomorrow, but If you know I would appreciate a response. How do I do Shift commands with the F keys. Such as Shift+F6. I know control is "^" ,but not sure on shift.

Edit: Figured it out - Send ("{LSHIFT}+{F6}") 

Edited by SkysLastChance

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites
water

Just as an information: You do not need to close Excel if it is already running. If the workbook you want to process is already open just use _ExcelBookAttach to connect to this workbook. If it fails (because the running Excel instance uses another workbook) use _ExcelBookOpen.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  

×