Function - Input: Web Colour Name - Output: Hex code for the input colour

Started by Wilhelm, April 16, 2015, 10:28:31 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Wilhelm

I posted a topic on changing hex colours to RGB(rrr,bbb,ggg) values yesterday and was rewarded with great answers -thanks.  The outflow of that topic was to find a function that will accept the web colour name (e.g. 'Green') and provide the hex colour code for it (e.g. 'Green' input would yield '#008000').

After quite an extensive search, I accepted that I wasn't going to find such a function in VBA that I could apply to my Visio 2010 solution, so I ended up writing the following simple function (see attached).  The reason I'm posting it here is to find out if anybody has an easier / better way of doing this, and also, if anybody else needs something in the interim, then they can use my solution.

Thanks

Wilhelm

I might add to this post:  The function was working fine when called directly once or twice, but it ended up getting quite resource intensive quite soon.  I have since revisited my thinking and added the colours in an array.  The attached should help - keep in mind, I used a fixed ColorArrary(0 to 146, 0 to 1).  A dynamic array would be even less resource intensive and will free up memory once erased.  This is Build1, so I'll hopefully update later.  Again, please let me know if you have a better way of doing this.