beboard Posted August 12, 2010 Share Posted August 12, 2010 Hi there, I'm trying to make a script that will take different actions depending on the color in an excel spreadsheet. I have this code but when I execute it nothing happens. Could anyone tell me what I'm doing wrong please ? Do Sleep(500) _WinWaitActivate("Microsoft Excel - Book1", "This is some text", 0) $var = PixelGetColor(1079, 172, 6) Select Case $var = 0xFFFF00 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0x3366FF MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0x00FF00 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0x000000 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0xFF0000 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) EndSelect Until $var = 0xFFFFFF Link to comment Share on other sites More sharing options...
Justforfun Posted August 12, 2010 Share Posted August 12, 2010 Hi there, I'm trying to make a script that will take different actions depending on the color in an excel spreadsheet. I have this code but when I execute it nothing happens. Could anyone tell me what I'm doing wrong please ? Do Sleep(500) _WinWaitActivate("Microsoft Excel - Book1", "This is some text", 0) $var = PixelGetColor(1079, 172, 6) Select Case $var = 0xFFFF00 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0x3366FF MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0x00FF00 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0x000000 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0xFF0000 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) EndSelect Until $var = 0xFFFFFF First take the _ off of your _winwaitactive so its WinWaitActive and then what res are you using so I can test on mine. Link to comment Share on other sites More sharing options...
beboard Posted August 12, 2010 Author Share Posted August 12, 2010 (edited) I took off the "_", it's still not working. I use 1280x1024 resolution. Thanks for replying. Also I forgot to mention. the click is to click the scroll down button in excel. Edited August 12, 2010 by beboard Link to comment Share on other sites More sharing options...
Justforfun Posted August 12, 2010 Share Posted August 12, 2010 (edited) Ok try this I had to change the hex color to make it work for me but your colors might be different so I changed it back to what you had Do Sleep(500) WinWaitActive("Microsoft Excel", "") ; Waits for Excel to be the active window $var = PixelGetColor(1079, 172) ; Gets pixel Hex color at x, y returns it as $ver Select Case $var = 0XFFFF00 ; If pixelgetcolor = any hex it will display msgbox MsgBox(1, "Hi", $var) MouseClick("main", 1270, 915, 1) ;Changed your 1's to "main" for button to be pressed for click Case $var = 0x3366FF MsgBox(1, "Hi", $var) MouseClick("main", 1270, 915, 1) Case $var = 0x00FF00 MsgBox(1, "Hi", $var) MouseClick("main", 1270, 915, 1) Case $var = 0x000000 MsgBox(1, "Hi", $var) MouseClick("main", 1270, 915, 1) Case $var = 0xFF0000 MsgBox(1, "Hi", $var) MouseClick("main", 1270, 915, 1) EndSelect Until $var = 0xFFFFFF ; Ends command if pixelgetcolor = hex color If that dont work then check your cords to see if they are matching the hex colors you have use this script I wrote real quick $var = PixelGetColor(1079, 172) ; Gets pixel Hex color at x, y returns it as $ver MsgBox(0,"hex color is", Hex($var, 6)) Hope this helps lety me know Edited August 12, 2010 by Justforfun Link to comment Share on other sites More sharing options...
seandisanti Posted August 13, 2010 Share Posted August 13, 2010 (edited) Hi there, I'm trying to make a script that will take different actions depending on the color in an excel spreadsheet. I have this code but when I execute it nothing happens. Could anyone tell me what I'm doing wrong please ? Do Sleep(500) _WinWaitActivate("Microsoft Excel - Book1", "This is some text", 0) $var = PixelGetColor(1079, 172, 6) Select Case $var = 0xFFFF00 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0x3366FF MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0x00FF00 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0x000000 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) Case $var = 0xFF0000 MsgBox(1, "Hi", $var) MouseClick(1, 1270, 915, 1) EndSelect Until $var = 0xFFFFFF Personally i'd go about it with com objects... the following code outputs color based on the color of the first cell... expandcollapse popup$oEx = ObjGet("","excel.application");attaches to existing excel application instance If IsObj($oEx) = 0 Then;checks for failure MsgBox(0,"Fail","Failed to attach to excel object");lets you know Exit;quits on fail EndIf $oWB = $oEx.ActiveWorkbook;once you've got an application, next step is grab a workbook if IsObj($oWB) = 0 Then;same test and output on fail except letting you know where it failed MsgBox(0,"Fail","Failed to attach to workbook object") Exit EndIf $oWS = $oWB.Activesheet;i just went with activesheet, but you can specify a sheet with $oWB.Worksheets(name or index) if IsObj($oWS) = 0 Then MsgBox(0,"Fail","Failed to attach to worksheet object") Exit EndIf $CI = $oWS.Range("a1").interior.colorindex; this is how you check the color of a cell... in this case the cell a1 ;the color is evaluated and responded to below ;these color codes are not hex colors obviously. can make a real quick color guide by doing a 1 to 56 for loop in excel ;just do: ;For $x = 1 to 56 ; $oWS.Range("a" & $x).Interior.ColorIndex = $x ;Next ;or you can do a script to identify colors already in use like: ;$whatever = InputBox("Cell","Enter cell coordinates to find out color") ;MsgBox(0,"Color","The color at cell " & $whatever & " is " & $oWS.Range($whatever).Interior.Colorindex) Select Case $CI = 1;then have your cases respond to the colors just like you had before MsgBox(0,"Color","The cell is black") Case $CI = 2 MsgBox(0,"Color","The cell is white") Case $CI = 3 MsgBox(0,"Color","The cell is red") Case $CI = 4 MsgBox(0,"Color","The cell is green") Case $CI = 5 MsgBox(0,"Color","The cell is blue") Case $CI = 1 MsgBox(0,"Color","The cell is yellow") EndSelect ***edit*** added comments and further examples Edited August 13, 2010 by cameronsdad Link to comment Share on other sites More sharing options...
beboard Posted August 13, 2010 Author Share Posted August 13, 2010 @justforfun your code did wonders thanks a lot for the help. @cameronsdad Thanks for the input but I'm afraid I'm a total newbie with autoit. I tried to put it in some while loop but when i executed it nothing happened. I don't think i know how to use it could you give me a few hints ? Link to comment Share on other sites More sharing options...
seandisanti Posted August 13, 2010 Share Posted August 13, 2010 @justforfun your code did wonders thanks a lot for the help. @cameronsdad Thanks for the input but I'm afraid I'm a total newbie with autoit. I tried to put it in some while loop but when i executed it nothing happened. I don't think i know how to use it could you give me a few hints ?the colors that you're reading; are they in specific cells or ranges on the worksheet? Link to comment Share on other sites More sharing options...
beboard Posted August 13, 2010 Author Share Posted August 13, 2010 the colors that you're reading; are they in specific cells or ranges on the worksheet?Each cell in column F has a different color which tells the script what action to take. That's why the script clicks the scroll down button each time after checking the color. I'm thinking your version might work better but it should know to go one row down after each pixelgetcolor. Link to comment Share on other sites More sharing options...
seandisanti Posted August 13, 2010 Share Posted August 13, 2010 Each cell in column F has a different color which tells the script what action to take. That's why the script clicks the scroll down button each time after checking the color. I'm thinking your version might work better but it should know to go one row down after each pixelgetcolor.yeah, directly controlling excel is easier and then it's not dependent on window, pixels, etc. i'll comment my code real quick, let me know if that helps... Link to comment Share on other sites More sharing options...
beboard Posted August 16, 2010 Author Share Posted August 16, 2010 Hi cameronsdad, I tried your code but it's still not working, it manages to attach to the excel workbook but still there is no msgbox displayed. Should I trigger it in any other way than just by running the script ? Link to comment Share on other sites More sharing options...
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