Set RGB Color - Excel

balta

Member
Hello,

i am trying to set a color shape in Excel using RGB

In this moment i am doing this.

Code:
ChExcel:selection:ShapeRange:Fill:ForeColor:RGB = ChFolha:ColorFormat:RGB(254, 94, 94) no-error.

I am reading this, but whiteout success.


Any have been able to do this in Excel? I want with HEX Color but Excel "force" to use RGB

Thanks
Baltazar
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
Seems more like an Excel question than an OpenEdge question.

I don't see an option for hex colour in the object model. Can you write a helper procedure/method to turn a hex colour string into RGB values?
 

balta

Member
I can try that.

In this moment, i have the problem to make work the code with RGB colors.

It is a Openedge/Excel question. How do i "convert" VBA object model to work in OE.

Do you have any example?

If that work, i will search a function to convert RGB to HEX.
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
It is a Openedge/Excel question. How do i "convert" VBA object model to work in OE.
You don't "convert" the object model. The model is conceptual: it tells you about the objects you can instantiate and manipulate, and their methods and properties, and relationships between objects.

You can implement code that uses the model in different languages, e.g. in VBA, in a macro-enabled workbook; or in ABL, via COM Automation. The code samples you will find online will likely be in VBA, or perhaps C#.

When I want to use ABL to programmatically create something in Excel (accepting that COM Automation is slower than molasses in January), I follow a process like this:
  • Design and create the finished product (worksheet/char/whatever) in Excel, manually.
  • Once I'm happy with the design, I create it again from scratch, with the Excel macro recorder enabled. This produces VBA code that should reproduce what I want. Of course this code won't be ideal. I will likely want to make it more efficient or flexible, e.g. parameterize hard-coded values, collect like operations into loops, etc. But importantly, it tells me which objects and methods/properties I should be using to get the result I want. It's very helpful when I'm dealing with an unfamiliar part of the object model
  • I write equivalent code in ABL syntax and then invoke it via an Excel.Application.
  • Test, debug, etc. There can be various pitfalls to resolve, e.g. the object model says a parameter is optional and OpenEdge thinks otherwise.
There are other ways to programmatically generate Excel workbooks, but this is what I do. It is relatively accessible for beginners.

It can also be helpful to use the OpenEdge COM Object Viewer utility to get an ABL-centric view of the objects, methods, and properties in a type library file. Run %DLC%\bin\proobjvw.exe and then open excel.exe. You should see something like this:

1664551081316.png
 

Osborne

Active Member
From Rob's screenshot HEX does not appear to be an option.

HEX can be set for some features but you have to know the value:

Code:
Range("A1"):Interior:Color = &HFFF744.
Range("A1"):Interior:Color = 16774980
 
Top