Jump to content

pixelgetcolor problem


Recommended Posts

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

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

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 by Justforfun
Link to comment
Share on other sites

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...

$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 by cameronsdad
Link to comment
Share on other sites

@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

@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

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

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...