Sign in to follow this  
Followers 0
JackieMcGee

Read array from Excel and run DOS command on the data

2 posts in this topic

Hi there,

Would really appreciate some help with this. I've created a gui with various buttons on it for some work I need to automate.

One of functions is that a XLS file will open containing lots of IP addresses (in column A), then I run the DOS Ping command on each cell and the results get written to a text file.

Heres what I did for one cell which worked fine:

Case $msg = $Button_6

#include <Excel.au3>

#include <Process.au3>

$sFilePath1 = @ScriptDir & "\ip.xls"

$oExcel = _ExcelBookOpen($sFilePath1)

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

$rc = _RunDos("ping " & $sCellValue & ">>c:\results.txt")

However, I am having trouble in running this for a whole vertical array of IP's. Heres what I got to so far:

Case $msg = $Button_5

#include <Excel.au3>

#include <Process.au3>

$sFilePath1 = @ScriptDir & "\ip2.xls"

$oExcel = _ExcelBookOpen($sFilePath1)

$aArray1 = _ExcelReadArray($oExcel, 1, 1, 5, 1) ;Direction is Vertical

$rc = _RunDos("ping " & $aArray1 & ">>c:\results2.txt")

How can I make the above DOS ping command be performed on each cell down column A?

Also...is it possible to send the results to another GUI window or another Excel sheet?

Very grateful for anyones help with this

Rgds

JP

Share this post


Link to post
Share on other sites



Create the array with an index and then just loop through the array:

$aArray1 = _ExcelReadArray($oExcel, 1, 1, 5, 1, 1) ;Direction is Vertical
For $iIndex = 1 to $aArray1[0]
 $rc = _RunDos("ping " & $aArray1[$iIndex] & ">>c:\results2.txt")
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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  
Followers 0