ich habe im diesem Forum folgendes Makro gefunden:
Public clrArt As Boolean
Sub ColorPicker()
Dim dlgFarben As DialogSheet
Dim btnOK As Button, btnCancel As Button
Dim optInterior As OptionButton, optFont As OptionButton
Dim txtClr As TextBox
Dim intRow As Integer, intCol As Integer
Dim l As Integer, t As Integer, intClr As Integer
Application.ScreenUpdating = False
Set dlgFarben = DialogSheets.Add
With dlgFarben
.Name = "dlgFarben"
With .DialogFrame
.Top = 0
.Left = 0
.Height = 200
.Width = 170
.Caption = "Color Picker"
End With
l = 15
t = 15
Set optInterior = .OptionButtons.Add(l, t, 75, 15)
optInterior.Caption = "Zellhintergrund"
optInterior.Value = xlOn
Set optFont = .OptionButtons.Add(l + 75, t, 75, 15)
optFont.Caption = "Schriftfarbe"
t = t + 20
For intRow = 1 To 7
l = 15
For intCol = 1 To 8
intClr = intClr + 1
Set txtClr = .TextBoxes.Add(l, t, 16, 16)
With txtClr
.Interior.ColorIndex = intClr
.OnAction = "FarbAuswahl"
.Name = "clr" & intClr
End With
l = l + 18
Next intCol
t = t + 18
Next intRow
Set btnOK = .Buttons(1)
Set btnCancel = .Buttons(2)
btnOK.Top = 180
btnOK.Left = 25
btnCancel.Top = 180
btnCancel.Left = 100
Worksheets(1).Select
.Show
Application.DisplayAlerts = False
.Delete
Application.DisplayAlerts = True
End With
End Sub
Sub FarbAuswahl()
Dim strAc As String
Worksheets("Tabelle1").Select
Range("a2:b4").Select
Application.ScreenUpdating = True
strAc = Application.Caller
If DialogSheets("dlgFarben").OptionButtons(1).Value = xlOn Then
Selection.Interior.ColorIndex = CInt(Right(strAc, Len(strAc) - 3))
UserForm1.TextBox1.BackColor = ...............?
Else
Selection.Font.ColorIndex = CInt(Right(strAc, Len(strAc) - 3))
UserForm1.TextBox1.ForeColor = ..........?
End If
End Sub
Es wird ein Bereich im Blatt farbig geändert (Hintergrund und Schrift). Da die Werte aus TextBox kommen wollte ich das auch die TextBox sich farbig anpasst (wie der Zellbereich auf dem Blatt).
Ist das möglich?
Ich habe so probiert:
UserForm1.TextBox1.ForeColor = CInt(Right(strAc, Len(strAc) - 3))
aber funktioniert nicht.
Gruss Thaddäus