Read the Conditional Formatting colors ? (1 Viewer)

smig

Registered User.
Local time
Today, 07:00
Joined
Nov 25, 2009
Messages
2,209
Is there any way to know the existing Conditional Formatting colors ?

I know how to set Conditional Formatting colors, but I can't find a way to set the exact colors I already used in another place :confused:
I want to be able to read either the Access color code, or RGB or HSL ...

Office 2016

Thanks.
 

smig

Registered User.
Local time
Today, 07:00
Joined
Nov 25, 2009
Messages
2,209
Thanks
It works great :)

feel free to use
Code:
Public Function fn_ReadConditionalFormat(frm As Form, strCntrl As String) As String

Dim i As Long

If frm.Controls(strCntrl).FormatConditions.Count > 0 Then
    For i = 0 To frm.Controls(strCntrl).FormatConditions.Count - 1
        fn_ReadConditionalFormat = fn_ReadConditionalFormat & frm.Controls(strCntrl).FormatConditions(i).Expression1
        fn_ReadConditionalFormat = fn_ReadConditionalFormat & " ==> ForeColor = " & frm.Controls(strCntrl).FormatConditions(i).ForeColor & "  " & VBA_Long_To_RGB(frm.Controls(strCntrl).FormatConditions(i).ForeColor)
        fn_ReadConditionalFormat = fn_ReadConditionalFormat & ", BackColor = " & frm.Controls(strCntrl).FormatConditions(i).BackColor & "  " & VBA_Long_To_RGB(frm.Controls(strCntrl).FormatConditions(i).BackColor)
        fn_ReadConditionalFormat = fn_ReadConditionalFormat & vbCrLf
    Next i
Else
    fn_ReadConditionalFormat = "No Conditional Format"
End If

End Function

Function VBA_Long_To_RGB(lColor As Long) As String
    
    Dim iRed, iGreen, iBlue
    
    'Convert Decimal Color Code to RGB
    iRed = (lColor Mod 256)
    iGreen = (lColor \ 256) Mod 256
    iBlue = (lColor \ 65536) Mod 256
    
    'Return RGB Code
    VBA_Long_To_RGB = "(" & iRed & ";" & iGreen & ";" & iBlue & ")"

End Function
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:00
Joined
Oct 29, 2018
Messages
21,473
Thanks
It works great :)

feel free to use
Code:
Public Function fn_ReadConditionalFormat(frm As Form, strCntrl As String) As String

Dim i As Long

If frm.Controls(strCntrl).FormatConditions.Count > 0 Then
    For i = 0 To frm.Controls(strCntrl).FormatConditions.Count - 1
        fn_ReadConditionalFormat = fn_ReadConditionalFormat & frm.Controls(strCntrl).FormatConditions(i).Expression1
        fn_ReadConditionalFormat = fn_ReadConditionalFormat & " ==> ForeColor = " & frm.Controls(strCntrl).FormatConditions(i).ForeColor & "  " & VBA_Long_To_RGB(frm.Controls(strCntrl).FormatConditions(i).ForeColor)
        fn_ReadConditionalFormat = fn_ReadConditionalFormat & ", BackColor = " & frm.Controls(strCntrl).FormatConditions(i).BackColor & "  " & VBA_Long_To_RGB(frm.Controls(strCntrl).FormatConditions(i).BackColor)
        fn_ReadConditionalFormat = fn_ReadConditionalFormat & vbCrLf
    Next i
Else
    fn_ReadConditionalFormat = "No Conditional Format"
End If

End Function

Function VBA_Long_To_RGB(lColor As Long) As String
    
    Dim iRed, iGreen, iBlue
    
    'Convert Decimal Color Code to RGB
    iRed = (lColor Mod 256)
    iGreen = (lColor \ 256) Mod 256
    iBlue = (lColor \ 65536) Mod 256
    
    'Return RGB Code
    VBA_Long_To_RGB = "(" & iRed & ";" & iGreen & ";" & iBlue & ")"

End Function
Hi. Congratulations! Glad to hear you got it working. Good luck with your project.
 

Users who are viewing this thread

Top Bottom