参考别人的代码做的 模块中定义 Type udtCColor
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As String
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As Long
End Type Declare Function ChooseColorA Lib "Comdlg32" _
(lpChooseColor As udtCColor) As Long
thisworkbook中 Public WithEvents xlApp As Excel.Application Private Sub Workbook_Open()
Set xlApp = Application
End Sub
Private Sub xlApp_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Cells.Interior.ColorIndex = 0
If Target.Row <> 1 And Target.Rows.Count = 1 Then
'Target.EntireRow.Interior.ColorIndex = 19
Dim CColor As udtCColor
Dim CustColors As String * 16
With CColor
.lStructSize = 36
.lpCustColors = CustColors
End With
If ChooseColorA(CColor) = 0 Then Exit Sub
Target.EntireRow.Interior.Color = CColor.rgbResult
End If
End Sub |