Samuel_Drake Posted September 17, 2019 Posted September 17, 2019 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. This 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.
seadoggie01 Posted September 17, 2019 Posted September 17, 2019 (edited) 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 September 17, 2019 by seadoggie01 Switch Example Samuel_Drake 1 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Reveal hidden contents My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
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