mailro Posted December 9, 2011 Posted December 9, 2011 (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. expandcollapse popup#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 December 12, 2011 by mailro
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now