Jump to content

Monitoring Changes in Variable Excel


Recommended Posts

#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>


; Create application object and open an example workbook
Local $var1= "D:\Documents\testbook.xls"
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, $var1)

Local $sRead = _Excel_RangeRead($oWorkbook, Default, "Q2")
Local $sRead2 = _Excel_RangeRead($oWorkbook, Default, "Q2")

$text1= "hello there"
$text2= "read me"

While 1=1
     If $sRead = $text1 Then
     ;MouseClick
     Consolewrite($sRead)
     Elseif $sRead2 = $text2 Then
     ;MouseClick
     Consolewrite($sRead2)
     EndIf
     sleep(30000);reads field every 30s
WEnd

Ok I am writing a script in excel that monitors a field that changes every so often then creates an action based on whether it is text1 or text2 I have problem here if I run script it will read the right text but if I go edit the text in excel it still displays the text before the change.

 

Thanks for your help.

Link to comment
Share on other sites

Try:

#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>


; Create application object and open an example workbook
Local $var1= "D:\Documents\testbook.xls"
Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, $var1)

Local $sRead

$text1= "hello there"
$text2= "read me"

While 1
    $sRead = _Excel_RangeRead($oWorkbook, Default, "Q2")
    If $sRead = $text1 Then
        ;MouseClick
        Consolewrite($sRead)
     Elseif $sRead = $text2 Then
        ;MouseClick
        Consolewrite($sRead)
     EndIf
     Sleep(30000);reads field every 30s
WEnd

 

Edited by Subz
No reason for $sRead2 so removed it.
Link to comment
Share on other sites

If the Workbook needs to be closed and re-opened (if modified from another program) you may need to do something like:

#include <Excel.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>


; Create application object and open an example workbook
Global $sWorkbook= "D:\Documents\testbook.xls"
Global $oExcel = _Excel_Open()
Global $oWorkbook, $sRead

Global $sText1= "hello there"
Global $sText2= "read me"

While 1
    $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook)
        $sRead = _Excel_RangeRead($oWorkbook, Default, "Q2")
    _Excel_BookClose($oWorkbook, False)
    If $sRead = $sText1 Then
        ;MouseClick
        Consolewrite($sRead)
     Elseif $sRead = $sText2 Then
        ;MouseClick
        Consolewrite($sRead)
    EndIf
    Sleep(30000);reads field every 30s
WEnd

 

Link to comment
Share on other sites

Another approach: Use events which get triggered as soon as a cell gets changed. See Worksheet Change Events in the example scripts forum.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

×
×
  • Create New...