AW: Farbpalette unter Excel 2007
31.01.2009 20:31:00
hary
Hallo Mathias
hatte ich mal auf der Office-Loesung Seite gefunden. Den Code in ein Modul.
Option Explicit
Private Type ChooseColor
lStructSize As Long
hwndOwner As Long
hInstance As Long
rgbResult As Long
lpCustColors As Long
flags As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As _
ChooseColor) As Long
Dim CustomColors(0 To 15) As Long
Public Function ShowColor(Optional PresetColor As Long = 0) As Long
Dim cc As ChooseColor
Dim lReturn As Long
Dim lShowColor As Long
cc.lStructSize = Len(cc)
cc.lpCustColors = VarPtr(CustomColors(0))
'flags
cc.flags = 0 'normal
'oder:
cc.flags = 2 'erweitert
'Show Color dialog
If ChooseColor(cc) 0 Then
ShowColor = cc.rgbResult
Else
ShowColor = PresetColor 'ggf.
End If
End Function
'Code Demo an beliebiger Stelle in deinem Project
Sub Demo_FarbeAuswaehlen()
Dim lngColor As Long
lngColor = ShowColor(-1)
If Not lngColor = -1 Then
MsgBox "Gewählte Farbe: " & lngColor, , "Demo"
Else
MsgBox "Abgebrochen", , "Demo"
End If
' Beispiele
Cells(7, 1).Font.Color = lngColor
'Range(Cells(7, 1), Cells(33, 2)).Font.Color = lngColor
'Range(Cells(7, 1), Cells(33 ,2)).Interior.Color = lngColor
End Sub
Gruss Hary