Setting colors in Hex and Decimal behaving differently

前端 未结 4 1231
攒了一身酷
攒了一身酷 2020-12-31 10:08

I am trying to set an orangish color in the following manner:

WorkSheet.Range(\"A1:A5\").Interior.color = 49407

and

WorkShe         


        
4条回答
  •  心在旅途
    2020-12-31 10:47

    This will convert the hex-format colors you have to the RGB Long that Office uses for RGB colors:

    Function HexToLongRGB(sHexVal As String) As Long
        Dim lRed As Long
        Dim lGreen As Long
        Dim lBlue As Long
    
        lRed = CLng("&H" & Left$(sHexVal, 2))
        lGreen = CLng("&H" & Mid$(sHexVal, 3, 2))
        lBlue = CLng("&H" & Right$(sHexVal, 2))
    
        HexToLongRGB = RGB(lRed, lGreen, lBlue)
    
    End Function
    

提交回复
热议问题