Jump to content

Recommended Posts

First of all, I am sorry to nag you with this newbie problem. I tried to find my answer on the forums but to no avail so I'm forced to make a topic.

I have an open Excel workbook on one display and I am trying to make a script to take certain action depending on what is written there.

image.png.a751dd950b3504208cb4e7318b8e09d4.pngThis is what I have in my Excel

My code is as such:

Global $testvar

WinActivate("Book1 - Excel")
Sleep(200)
Send("{DOWN 2}{RIGHT}")
Sleep(200)
Send("^c")
Sleep(200)
$testvar = ClipGet()
Sleep(200)

Select
    Case $testvar = "Sleep"
        Send("{RIGHT}")
    Case $testvar = "Mouse Click"
        Send("{DOWN}")
    Case Else
        Send("{RIGHT}{DOWN}")
EndSelect

I can not make the script compare $testvar with any string. Even if I were to use "==" instead of "=" for comparison.

I can use numeric values for comparasion no problem, but I need strings.

Link to post
Share on other sites

Welcome!

I would suggest looking into Water's Excel UDF, it's great and I use it daily. You could use something like this:

#include <Excel.au3> ; (This is a built-in UDF, so you don't have to download anything)

; Open Excel (will attach if possible)
Local $application = _Excel_Open()
If @error then ConsoleWrite("Excel_Open: " & @error & @CRLF)

; Open the workbook... Use _Excel_BookAttach if it's already open
Local $workbook = _Excel_BookOpen($application, $ExcelFileFullPath)
If @error then ConsoleWrite("Excel_BookOpen: " & @error & @CRLF)

; Read the cell's value
ConsoleWrite("Cell Value: " & _Excel_RangeRead($workbook, "SheetName", "C3") & @CRLF)
If @error then ConsoleWrite("Excel_RangeRead: " & @error & @CRLF)

As for your select statement, I would usually use Switch instead because you're only testing if your variable is equal to one thing... see here: https://www.autoitscript.com/autoit3/docs/intro/lang_conditional.htm

Switch $testvar
    Case "Sleep"
        ; Sleep stuff
    Case "Stop", "Exit"
        ; other stuff
    Case Else
        ConsoleWrite($testvar & @CRLF)
EndSwitch

 

Edited by seadoggie01
Switch Example

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...