VBA - use color already select in Excel to fill cell interior

前端 未结 3 2007
礼貌的吻别
礼貌的吻别 2021-01-18 14:31

I know how to set the interior color of a cell to a certain color, but is there a way to do it so that it (i.e., the cell color) defaults to the color already selected in th

3条回答
  •  一整个雨季
    2021-01-18 15:29

    I'm afraid you can't

    Anyway, you can use a custom palette using this code:

    The modColorFunctions module contains a function named ChooseColorDialog that will display a Windows Color Picker dialog and return the RGB Long color value. If the user cancels the dialog, the result is -1. For example,

    Dim RGBColor As Long
    Dim Default As Long
    Default = RGB(255, 0, 255) 'default to purple
    RGBColor = ChooseColorDialog(DefaultColor:=Default)
    If RGBColor < 0 Then
        Debug.Print "*** USER CANCELLED"
    Else
        Debug.Print "Choice: " & Hex(RGBColor)
    End If
    

    Taken from the chapter Displaying A Color Picker Dialog of http://www.cpearson.com/Excel/Colors.aspx

    You need to add the color module to make it work

提交回复
热议问题