Sign in to follow this  
Followers 0
mailro

Autoit to Excel Macro

1 post in this topic

#1 ·  Posted (edited)

Hi,

I have the following code in Autoit that, writes data from Excel on value change

and I want to make it an Excel Macro if someone can help I would be greatfull.

#include <Excel.au3>
OnAutoItExitRegister("CleanExit")
Global $result, $PResult
$sFilePath = "C:Documents and SettingsAdministratorDesktopAT_SRLevel_II.xls"
_ExcelBookOpen($sFilePath)
$oExcel = _ExcelBookAttach($sFilePath)
While 1
$aLevels = _ExcelReadArray($oExcel, 14, 5, 11, 0) ;
$aAsks = _ExcelReadArray($oExcel, 15, 5, 11, 0) ;
$aBids = _ExcelReadArray($oExcel, 16, 5, 11, 0) ;
$aBA = _ExcelReadArray($oExcel, 17, 5, 11, 0) ;
$aLevels[0] = "Levels"
$oLevels = ""
$oAsks = ""
$oBids = ""
$oBA = ""
For $i = 0 To 10
  If $i < 10 Then
   $Separator = ";"
  Else
   $Separator = ""
  EndIf
  $oLevels = $oLevels & $aLevels[$i] & $Separator
  $oAsks = $oAsks & $aAsks[$i] & $Separator
  $oBids = $oBids & $aBids[$i] & $Separator
  $oBA = $oBA & StringLeft($aBA[$i], 4) & $Separator
Next
$PResult = $result
$result = $oLevels & @CRLF & $oAsks & @CRLF & $oBids & @CRLF & $oBA
If $result <> $PResult Then WritetoDisk($result)
Sleep(1)
WEnd
Func WritetoDisk($input)
$file = FileOpen("test.txt", 1)
FileWrite($file, $input & @CRLF & @CRLF)
FileClose($file)
EndFunc   ;==>WritetoDisk
Func CleanExit()
_ExcelBookClose($oExcel, 1, 0)
EndFunc   ;==>CleanExit

The reason I want it to be an excel macro is that the excel cells are been updated from a RTD stream. When the updates goes wild the autoit code crashes because the OLE mechanism isn't fast enough to catch up with the RTD.

The error message is

C:Program Files (x86)AutoIt3IncludeExcel.au3 (734) : ==> The requested action with this object has failed.:

$aArray[$xx] = $oExcel.Activesheet.Cells($iStartRow, ($xx - $iIndexBase) + $iStartColumn).Value

$aArray[$xx] = $oExcel.Activesheet^ ERROR

Edited by mailro

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