+ Reply to Thread
Results 1 to 31 of 31

Question on how to populate Color property of Excel objects, i.e backcolor?

  1. #1
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Question on how to populate Color property of Excel objects, i.e backcolor?

    Hi all, I am putting a button on a sheet and I would like to use a specific colour, not one of the default ones provided by Excel.
    I can obviously get the colour definition in RGB or Hex, but Excel seems to want a format that I am not familiar with, and have been unable to find any information on.

    For example, a red shade is defined like this: &H000040C0&

    Where can I find information on how to get the codes that Excel accepts so I can make my objects the shade of colour that I am after....?

    Hope somebody can help!

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Where do you find the &H000040C0& reference?

    I use excel 2003, I can assign a objects colour as RGB by going to format autoshape -> colours and lines -> selecting the colour drop down -> more colours -> custom tab.

    You can then use either RGB or HSL colour models to put custom colours in.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    The last 6 digits, 0040C0, of &H000040C0& are the RGB for the colour.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by Norie View Post
    The last 6 digits, 0040C0, of &H000040C0& are the RGB for the colour.
    That can't be right, can it? There are no letters in RGB.... Besides, there can be up to 3 digits for each of the Red, Green, Blue shades, so that format ought not cover it...

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?


  6. #6
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    If it is Hex, then it needs some serious formatting.

    The current format is "&H00008000&" for a Dark Green color. This code does not look like Hex. The Hex for any shade of green that I know, does not look like that at all. Neither does the RGB code.

    But if it is somehow hex anyway, then please could you help me to explain how to convert the hex for Green into the format that Excel apparently needs, to understand what colour this is?

    Steps to reproduce:
    1) Put an object Button on an Excel sheet.
    2) Select Properties and then check the 5th option from the top, which is backcolor. This allows you to select default colours to change the colour of the button, but there is also a code available. This is the code I am talking about, and it does NOT look like Hex or RGB to me.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Perhaps you could take a look at the RGB function.

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    It is hex, google "#008000" it's dark green

    Have a look here for conversions: http://www.colorhexa.com/008000

  9. #9
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by Norie View Post
    Perhaps you could take a look at the RGB function.
    I am very well familiar with RGB since I have been a java programmer for many years.

    I am not looking for a function here, but a property, and I am not looking to learn VBA programming, just understand how I can change the colour of the button to the colour that I want.

    Colour Red:
    -------------------------
    RGB colour format = RGB(255, 0, 0)
    Excel object property format = &H00008000&

    ???

    I see no correlation, but if there is one I would be really grateful for a straightforward answer, or a link to a page that definitely explains how this works. Checking the Excel RGB function, it does not indicate how to set the button property to a specific shade.

  10. #10
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by Kyle123 View Post
    It is hex, google "#008000" it's dark green

    Have a look here for conversions: http://www.colorhexa.com/008000
    That looks more promising, I'll check it. Thanks!



    Edit - No, this is not it either. :-(

    Excel seems to want a code starting with "&" (ampersand) followed by "H", then 7 numbers, then the letter "C" and another ampersand, like this: "&H00008000&"

    There is nothing on that page that comes up with the colour I'd expect based on any of the formats on the page. Trying to input the numbers/letters from RGB or hex gives an error or a completely unexpected colour.


    I can get the button to randomly change colour by changing the digits in the 7 number string, but as of right now, it's completely random, I don't see any logic as to how it changes.


    For example, black, like Excel's default font colour, seems to be &H80000012& (ForeColor property)


    ---------------------

    This PDF explains how this is not actually colours but a semi-dynamic reference to a holder in Windows. http://www.johnsmiley.com/cis18/Smiley009.pdf
    Meaning that what settings you got in these colour holders in the Windows colour scheme, specifies what colour you get from these codes.

    Hence, me choosing one particular colour, might produce a completely different colour on an olde machine, or a machine where the user has heavily customised the colour scheme.

    In other words, this property is more or less useless as it is not consistent or reliable at all.
    Last edited by johanna0507; 12-02-2013 at 09:49 AM.

  11. #11
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Johanna,

    I think Norie meant, in answer to your question on how to convert between the format used by excel (HEX) and RGB format, you can use the RGB funtion in VBA.

  12. #12
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by yudlugar View Post
    Johanna,

    I think Norie meant, in answer to your question on how to convert between the format used by excel (HEX) and RGB format, you can use the RGB funtion in VBA.

    Thanks - unfortunately I do not know VBA programming and do not have time to learn it.
    I just wanted to turn a button on a spreadsheet into the colour of my choice. The only function of the button is to activate another tab. This is ridiculously simple stuff, but something that my boss asked me to include for this spreadsheet.

    I had NO idea that setting the button colour would be this complicated, and it seems that what I want to achieve (i.e. set the colour of the button to my exact preference of colour) is not in fact possible, or not possible unless I learn VBA programming first, which I do not want to do.
    Last edited by johanna0507; 12-02-2013 at 09:53 AM.

  13. #13
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    If you know the RGB values you wish to use, you may input them directly to the property. Click the dropdown button in the property you require, select the Palette tab and then right-click an empty colour square.

  14. #14
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    did you see what I put in post #2?

  15. #15
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    HEX colours in VB6 aren't RRGGBB, they are BBGGRR, so if I wanted #cc0000, it would become: "&H000000CC" as a string or &H000000CC& which is &HCC& as long note the ampersand

  16. #16
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by yudlugar View Post
    did you see what I put in post #2?
    I have Excel 2010 and I checked for anything resembling what you were talking about, but could not find it. There was a MAJOR change in the GUI for Excel between 2003 which you are using, and 2010 which I am using. There is nothing called "Color Autoshape" anywhere that I can spot, in the Excel 2010 GUI.

    Quote Originally Posted by Izandol
    If you know the RGB values you wish to use, you may input them directly to the property. Click the dropdown button in the property you require, select the Palette tab and then right-click an empty colour square.
    Hi, Yes I can select a blank square (no colour). But no variation of inputting the RGB code seems to work. I've tried:
    • 255,0,0
    • RGB(255,0,0)
    • 25500 (this adds the ampersand and the letters, but creates an Orange-brown shade) rather than Red as it is supposed to do

    Would you be able to explain how to change the RGB so that it works?
    Last edited by johanna0507; 12-02-2013 at 10:05 AM.

  17. #17
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by Kyle123 View Post
    HEX colours in VB6 aren't RRGGBB, they are BBGGRR, so if I wanted #cc0000, it would become: "&H000000CC" as a string or &H000000CC& which is &HCC& as long note the ampersand
    Hi yes, thanks! I came across this when googling, but it did still not tell me the format.
    I'll check, based on your suggestion.

    However RGB, can take between 3 and 9 digits - the format you list seems to suggest 2 digits x 3 ?



    I take as an example, a sort of Heather shade of Purple RGB(149,102,138)
    So I make this 138102149

    No variation of trying to enter this into the Back Color property field for the object works - get an error whatever I put.
    Last edited by johanna0507; 12-02-2013 at 10:09 AM.

  18. #18
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Hi Johanna, the same option exists in 2010 I believe.

    When you right click on a shape in 2010 and go to format shape, there is an option for fill in the menu on the left hand side.

    You can then check the option for solid fill and when you click the drop down color palette the bottom line says "more colours"

    if you click this you get the same form you get in 2003, where you can select custom and and input using either RGB or HSL colour models.

  19. #19
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by yudlugar View Post
    Hi Johanna, the same option exists in 2010 I believe.

    When you right click on a shape in 2010 and go to format shape, there is an option for fill in the menu on the left hand side.

    You can then check the option for solid fill and when you click the drop down color palette the bottom line says "more colours"

    if you click this you get the same form you get in 2003, where you can select custom and and input using either RGB or HSL colour models.
    Hi - no; I right click and get Format Object and Properties as the relevant choices. Neither allows to set the colour in an easy way. This was the first thing I checked for. The closest I've been able to get, is this property that I'm talking about. The commands for changing colour etc in the menu tabs are greyed out since it's an object and not a regular cell or text.

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Johanna

    Is this a Forms or ActiveX button?

  21. #21
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    No, you can't just put RGB values into a hex format, the hex code for RGB(149,102,138) is #95668a, which would be: &H8A6695

  22. #22
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Johanna,

    Apologies, I thought we were talking about shapes here (try doing what I said on a rectangle..) I wasn't aware you could change the background colour of a forms/activex control. My understanding was that you got around this by using a rectangle shape and assigning the macro to the onclick event.

  23. #23
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by johanna0507 View Post
    Hi, Yes I can select a blank square (no colour). But no variation of inputting the RGB code seems to work. I've tried:
    Would you be able to explain how to change the RGB so that it works?
    If you right-click a blank square you will see a dialog that allows you to choose RGB values as well as HSL. Select what you need then Add Color. If you choose an existing colour, nothing will be added, but you can simply select that colour for your button and then press OK.

  24. #24
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    yudlugar

    I don't think you can change the back colour of a Forms button, not without code anyway and I'm not even sure code will work.

  25. #25
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by Norie View Post
    Johanna

    Is this a Forms or ActiveX button?
    Good question, I didn't actually know, but upon checking it turns out it's an Active X button (copied it from another sheet, and frankly didn't realise Excel catered for Active X at all.... )

    I certainly don't need Active X, since all I want the button to do, is open another tab.

    I'll change the button to a regular button in which case this might be easier.

    Still on the Form button I cannot find the colour property there either, but it seems to look quite different, so I might have been down the complete wrong road here.

    Seems the button colour is somehow tied in with the Windows colour chart and I am beginning to think I am wasting a silly amount of time on something that is purely cosmetic.

  26. #26
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    A Forms button doesn't have a back colour property, an ActiveX button does.

  27. #27
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Did you read my post?

    Here's a function to do what you want:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Last edited by Kyle123; 12-02-2013 at 10:44 AM.

  28. #28
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by Kyle123 View Post
    No, you can't just put RGB values into a hex format, the hex code for RGB(149,102,138) is #95668a, which would be: &H8A6695

    Thanks - ok, so it was the Hex that should be reversed, not the RGB - ok. Thanks!

  29. #29
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by Kyle123 View Post
    Did you read my post?

    Here's a function to do what you want:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Hi - thanks for that. Sorry, for some reason I did not see the code.
    thanks a lot for doing that.
    I'm have never done any programming with VBA and I do not have the time to learn it now.
    i don't think I can use this code because I wouldn't know where to put it.

    I was under the (clearly misguided) impression that throwing in a button with some simple code in the Clicked event, to move tabs, and using different colours, would be the simplest thing in the world.

    I think i was misguided here, and I believe I have been wasting all of your time, and mine.
    Since I am not a VBA programmer, but a project manager, I can not spend time trying to figure out stuff like this with trial and error, or reading manuals - If I can't do it quickly, or get a quick clear response that I am able to follow, i will have to pass.

  30. #30
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Try adding a rectangle, or other shape, to the sheet, then right clicking it and selecting Hyperlink...

    You should then be able to create a hyperlink to an other sheet that will be followed when you click the shape.

    To change the Fill colour of the shape right click and select Format...

    PS When you click colour in the Fill section there's an option More colours... that will display a colour palette and the RGB for the colour you choose.

  31. #31
    Registered User
    Join Date
    12-21-2011
    Location
    EU here and there
    MS-Off Ver
    Excel 2019
    Posts
    69

    Re: Question on how to populate Color property of Excel objects, i.e backcolor?

    Quote Originally Posted by Norie View Post
    Try adding a rectangle, or other shape, to the sheet, then right clicking it and selecting Hyperlink...

    You should then be able to create a hyperlink to an other sheet that will be followed when you click the shape.

    To change the Fill colour of the shape right click and select Format...

    PS When you click colour in the Fill section there's an option More colours... that will display a colour palette and the RGB for the colour you choose.
    Good tip, thanks!!! Might try that. I think I'll have to cut my losses with this, and just to the quickest workaround I can find. What you propose sound fast.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding objects as a property of cells/range
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2013, 03:12 AM
  2. TextBoxes backcolor as cells color
    By john55 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-26-2011, 12:53 PM
  3. Objects with .type property
    By atpgroups in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-02-2006, 07:05 AM
  4. Question - How to group unique objects in Excel
    By bradsaxon in forum Excel General
    Replies: 1
    Last Post: 04-14-2006, 12:55 PM
  5. Populate fields From excel file to Web form/objects
    By ilyaskazi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-14-2005, 02:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1