Thread: color function
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Peter T[_3_] Peter T[_3_] is offline
external usenet poster
 
Posts: 81
Default color function

You have the low down as to why a udf cannot directly
apply formats etc.
However I find it is possible for a udf to trigger a
normal macro (to do the formatting) by using SendKeys to
send an already created keyboard shortcut to the macro.
You also need some global variables to store the arguments
of the function for use by the macro.

Also as explained by others, an applied format will be one
of the existing 56 palette colours, the nearest matched.
If you want to apply your own colour, customize a
colorindex with the macro, then apply same colorindex as
the format. Add an extra argument for cIndex:
Activeworkbook.colors(cIndex) = value

The udf / sendkeys / macro method is far from satisfactory
for general use. At the very least may need other things
to avoid problems, depending on the context. However I did
develop an instant palette customizer based on this
approach that seems to work.

Regards,
Peter

-----Original Message-----
I would like to write a function that will color the

interior of a cell
according to RGB values.

This is my code:
Function InteriorColor(ByVal R as Integer, ByVal G as

Integer, ByVal B as
Integer)
ActiveCell.Interior.Color = RGB(R, G, B)
End Function

This simple code refuse to work when I call it from a

worksheet, although it
works well when activates him from another subroutine.
What is wrong ?!!

Thanks for the help

Avner
R&D Physicist
email:


.