Jump to content

How can i set excel cell color with RGB color


Recommended Posts

Hello

I get problem with excel cell color. I'm trying to use this code:

#include <ExcelCOM_UDF.au3>
$oExcel = _ExcelBookNew()
$oExcel.ActiveWorkbook.Sheets(1).cells(1,1).Interior.Color = "RGB(255, 0, 0)"

this code work in VB excel

And i got this error:

C:Documents and SettingsbinhngoDesktopautoitexhtml.au3 (73) : ==> The requested action with this object has failed.:
$oExcel.ActiveWorkbook.Sheets(1).cells(1,1).Interior.Color = "RGB(255, 0, 0)"
$oExcel.ActiveWorkbook.Sheets(1).cells(1,1).Interior^ ERROR

when i try use

$oExcel.ActiveWorkbook.Sheets(1).cells(1,2).Interior.Color = 702623
;or
$oExcel.ActiveWorkbook.Sheets(1).cells(1,2).Interior.ColorIndex = 16

it's worked. But the problem here is: i have 6 digit hex color and i can only convert it to RGB color (for ex:d6834d).

how can i set RGB color for excel cell using Autoit, please help

Edited by luckyluke
Link to comment
Share on other sites

  • 1 year later...

I got confused by the non-standard ordering of luckyluke's formula (BGR vs. RGB).

I think it's more natural when written in RGB order, as most people are used to:
 

R + (G*256) + (B*256*256)

 
I assigned the result of this calculation to:
 

$range.interior.color = ...
Edited by MC256
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...