Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 11-24-2014, 04:15 AM
Hoggle42 Hoggle42 is offline Converting color codes in VBA Windows 7 64bit Converting color codes in VBA Office 2013
Novice
 
Join Date: Nov 2014
Posts: 1
Hoggle42 is on a distinguished road
Default

As a companion to that function (very useful btw, thanks)

This one converts a VBA colour code to a six character hex code useable in CSS etc. Not sure if the blue and green are wrongly labelled, but the order is correct (it produces the right colour). The Hex function returns "0" rather than "00" so it needs padding.

Code:
Private Function fcnLongToHex(ByRef lngColor As Long) As String
    Dim hRed, hGreen, hBlue
    hRed = Hex(lngColor Mod 256)
    If Len(hRed) = 1 Then hRed = "0" & hRed
    hGreen = Hex((lngColor \ 256) Mod 256)
    If Len(hGreen) = 1 Then hGreen = "0" & hGreen
    hBlue = Hex((lngColor \ 256 \ 256) Mod 256)
    If Len(hBlue) = 1 Then hBlue = "0" & hBlue
    fcnLongToHex = hRed & hBlue & hGreen
End Function
Reply With Quote
 

Tags
color, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting color codes in VBA Codes Popping Up In My Text? Faedrie Word 1 11-08-2012 01:00 AM
Converting color codes in VBA Codes for Word Textbox Font Color? tinfanide Word VBA 7 10-23-2012 03:13 PM
Converting color codes in VBA Losing VBA codes in .dotm tinfanide Word VBA 15 04-12-2012 12:39 AM
Converting color codes in VBA Outline Codes eliz.bell Word 4 03-28-2012 07:27 PM
Why run-time is always different from stepping into the codes? tinfanide Excel Programming 1 03-04-2012 12:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:29 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft