Hi,
...mehrere in Userform zur Auswahl haben.
da meine Frage in diesem Tread
https://www.herber.de/forum/archiv/1380to1384/t1380538.htm#1381566
noch offen war, aber geschlossen wurde, solls hier weitergehen
gruss Ivonne.
Hi,
...mehrere in Userform zur Auswahl haben.
da meine Frage in diesem Tread
https://www.herber.de/forum/archiv/1380to1384/t1380538.htm#1381566
noch offen war, aber geschlossen wurde, solls hier weitergehen
gruss Ivonne.
Private Sub Image1_Click()
frmFarben.Hide
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim c As Range
For Each c In Selection
c.Interior.Color = xlNone
Next
frmFarben.Hide
End Sub
Private Sub UserForm_Initialize()
Call Farbensetzen
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
MsgBox "Bitte benutzen sie oben links das rote Image zum Verlassen des Formulars.", _
vbInformation, "Abbruch"
Cancel = True
End If
End Sub
Damit ist die Userform fertig.Public cLabel() As New clsLabel
Public cButton() As New clsButton
Public mycontrol As String
Public myadr As String
Public Bereich As Range
Public Dateiname As String
Public Dateipfad As String
Public Start As Long
Sub Farbensetzen()
Dim myleft As Integer
Dim tbcount As Integer
Dim i As Long
Dim k
Dim l
Dim m
Dim s As Long
Dim t As Long
Dim u As String
Dim w As Long
Dim x As Long
Dim Y As Long
Dim z As Long
Dim Farbe
Dim newtb As Control
Dim myarr
On Error Resume Next
myleft = 5
ReDim myarr(1)
myarr = Array(36, 2, 20, 6, 26, 30, 31, 32, 34, 37, 40, 42)
s = 1
t = 1
Farbe = &H80000005
With frmFarben
For m = 1 To 3
x = 10
Y = 50
For l = 1 To 4
Set newtb = .Controls.Add("Forms.Textbox.1")
With newtb
.Name = "TB" & t
.Left = myleft
.Top = Y
.Width = 55
.Height = 15
.BackColor = &H80000005
.ForeColor = &HFF&
.SelectionMargin = False
.Enabled = True
.Font.Bold = True
.Text = lesen(CDbl(myarr(t - 1)))
If .Text = "Standard" Then .Text = "Larissa"
End With
t = t + 1
Y = Y + 100
w = myleft + 60
Start = s
For k = 1 To 6
For i = 1 To 12
Set newtb = .Controls.Add("Forms.Label.1")
With newtb
.Name = "Label" & s
.Left = w
.Top = x
.Width = 10
.Height = 10
.TextAlign = 2
.BackColor = &H80000002
.BorderStyle = 1
.Font.Size = 10
End With
w = w + 15
s = s + 1
Next
x = x + 15
w = myleft + 60
Next
Call Farben
x = x + 10
Next
myleft = myleft + 240
Next
Set newtb = .Controls.Add("Forms.CommandButton.1")
With newtb
.Name = "CB1"
.Caption = "Weitere Farben"
.Left = 350
.Top = x
.Width = 100
.Height = 20
.TextAlign = 2
.BackColor = &HC0FFFF
.BorderStyle = 1
.Font.Size = 10
End With
x = x + 30
For Each newtb In frmFarben.Controls
If TypeName(newtb) = "Label" Then
tbcount = tbcount + 1
If tbcount > 1 And tbcount < 900 Then
ReDim Preserve cLabel(1 To tbcount)
Set cLabel(tbcount).Label = newtb
End If
End If
Next newtb
For Each newtb In frmFarben.Controls
If TypeName(newtb) = "CommandButton" Then
tbcount = tbcount + 1
If tbcount > 1 And tbcount < 900 Then
ReDim Preserve cButton(1 To tbcount)
Set cButton(tbcount).Button = newtb
End If
End If
Next newtb
End With
frmFarben.Top = 0
frmFarben.Left = 0
frmFarben.Width = 730
frmFarben.Height = x + 15
frmFarben.Show
End Sub
Function lesen(Index As Long) As String
Dim Ordner As String
Dim Liste As String
Dim myarr(42) As Variant
Dim i As Long
Dim fo As Object
Dim fi As Object
Dim fso As Object
Ordner = "c:\Program Files\Microsoft Office\Document Themes 14\Theme Colors\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fo = fso.GetFolder(Ordner)
i = 0
For Each fi In fo.Files
myarr(i) = Left(fi.Name, Len(fi.Name) - 4)
i = i + 1
Next
lesen = myarr(Index - 1)
Dateiname = lesen & ".xml"
Dateipfad = Ordner & Dateiname
End Function
Sub Farben()
Dim i
Dim k
Dim x
Dim arr
ReDim arr(1 To 5)
arr(1) = Array(-0.049989319, 0.499984741, -0.99948119, 0.799981689, 0.799981689, 0.799981689, _
0.799981689, 0.799981689, 0.799981689, 0.799981689, 0.799981689, 0.799981689)
arr(2) = Array(-0.149967956, 0.349986267, -0.249946593, 0.599963378, 0.599963378, 0. _
599963378, 0.599963378, 0.599963378, 0.599963378, 0.599963378, 0.599963378, 0.599963378)
arr(3) = Array(-0.249946593, 0.249946593, -0.499984741, 0.399945067, 0.399945067, 0. _
399945067, 0.399945067, 0.399945067, 0.399945067, 0.399945067, 0.399945067, 0.399945067)
arr(4) = Array(-0.349986267, 0.149967956, -0.749961852, -0.249946593, -0.249946593, -0. _
249946593, -0.249946593, -0.249946593, -0.249946593, -0.249946593, -0.249946593, -0.249946593)
arr(5) = Array(-0.499984741, 0.049989319, -0.899960326, -0.499984741, -0.499984741, -0. _
499984741, -0.499984741, -0.499984741, -0.499984741, -0.499984741, -0.499984741, -0.499984741)
ActiveWorkbook.Theme.ThemeColorScheme.Load (Dateipfad)
With frmFarben
.Controls("Label" & Start).BackColor = ThisWorkbook.Theme.ThemeColorScheme.Colors(2)
.Controls("Label" & (Start)).ControlTipText = .Controls("Label" & (Start)).BackColor
.Controls("Label" & (Start + 1)).BackColor = ThisWorkbook.Theme.ThemeColorScheme.Colors(1)
.Controls("Label" & (Start + 1)).ControlTipText = .Controls("Label" & (Start + 1)). _
BackColor
.Controls("Label" & (Start + 2)).BackColor = ThisWorkbook.Theme.ThemeColorScheme.Colors(4)
.Controls("Label" & (Start + 2)).ControlTipText = .Controls("Label" & (Start + 2)). _
BackColor
.Controls("Label" & (Start + 3)).BackColor = ThisWorkbook.Theme.ThemeColorScheme.Colors(3)
.Controls("Label" & (Start + 3)).ControlTipText = .Controls("Label" & (Start + 3)). _
BackColor
For i = 4 To 11
.Controls("Label" & (Start + i)).BackColor = ThisWorkbook.Theme.ThemeColorScheme.Colors(i + _
1)
.Controls("Label" & (Start + i)).ControlTipText = .Controls("Label" & (Start + i)). _
BackColor
Next
For i = 12 To 23
.Controls("Label" & (Start + i)).BackColor = Col(.Controls("Label" & (Start + i - 12)). _
BackColor, CDbl(arr(1)(i - 12)))
.Controls("Label" & (Start + i)).ControlTipText = .Controls("Label" & (Start + i)). _
BackColor
Next
For i = 24 To 35
.Controls("Label" & (Start + i)).BackColor = Col(.Controls("Label" & (Start + i - 24)). _
BackColor, CDbl(arr(2)(i - 24)))
.Controls("Label" & (Start + i)).ControlTipText = .Controls("Label" & (Start + i)). _
BackColor
Next
For i = 36 To 47
.Controls("Label" & (Start + i)).BackColor = Col(.Controls("Label" & (Start + i - 36)). _
BackColor, CDbl(arr(3)(i - 36)))
.Controls("Label" & (Start + i)).ControlTipText = .Controls("Label" & (Start + i)). _
BackColor
Next
For i = 48 To 59
.Controls("Label" & (Start + i)).BackColor = Col(.Controls("Label" & (Start + i - 48)). _
BackColor, CDbl(arr(4)(i - 48)))
.Controls("Label" & (Start + i)).ControlTipText = .Controls("Label" & (Start + i)). _
BackColor
Next
For i = 60 To 71
.Controls("Label" & (Start + i)).BackColor = Col(.Controls("Label" & (Start + i - 60)). _
BackColor, CDbl(arr(5)(i - 60)))
.Controls("Label" & (Start + i)).ControlTipText = .Controls("Label" & (Start + i)). _
BackColor
Next
End With
End Sub
Function Col(Color As Long, Tas As Double) As Long
Dim r
Dim R1
Dim g
Dim G1
Dim b
Dim B1
r = Color Mod 256
g = (Color \ 256) Mod 256
b = (Color \ 256 \ 256) Mod 256
If Tas > 0 Then
R1 = r + WorksheetFunction.RoundUp(Tas * (255 - r), 0)
G1 = g + WorksheetFunction.RoundUp(Tas * (255 - g), 0)
B1 = b + WorksheetFunction.RoundUp(Tas * (255 - b), 0)
Else
R1 = r + WorksheetFunction.RoundDown(Tas * r, 0)
G1 = g + WorksheetFunction.RoundDown(Tas * g, 0)
B1 = b + WorksheetFunction.RoundDown(Tas * b, 0)
End If
If R1 < 0 Then r = 0
If G1 < 0 Then g = 0
If B1 < 0 Then b = 0
Col = RGB(R1, G1, B1)
End Function
Sub farbdialog()
frmFarben.Show
End Sub
nun noch zwei Klassenmodule einfügenPublic WithEvents Button As MSForms.CommandButton
Private Sub Button_Click()
Application.Dialogs(xlDialogPatterns).Show
End Sub
das zweite umbenennen in "clsLabel" und dort folgenden Code einfügen.Public WithEvents Label As MSForms.Label
Private Sub Label_Click()
Dim c As Range
For Each c In Selection
c.Interior.Color = Label.BackColor
Next
frmFarben.Hide
End Sub
Das wäre dann schon alles im VB-Editor und er kann geschlossen werden.myarr = Array(36, 2, 20, 6, 26, 30, 31, 32, 34, 37, 40, 42)
damit deine Auswahl erscheint gebe in der Klammer deine notierten Zahlen ein.Function SelectColor(Optional lngInitialColor As Long = 16777215) As Long
Dim lngResult As Long, lngO As Long, intR As Integer, intG As Integer, intB As Integer
lngResult = xlNone
If Not ActiveWorkbook Is Nothing Then
lngO = ActiveWorkbook.Colors(1)
intR = lngInitialColor And 255
intG = lngInitialColor \ 256 And 255
intB = lngInitialColor \ 256 ^ 2 And 255
If Application.Dialogs(xlDialogEditColor).Show(1, intR, intG, intB) = True Then
lngResult = ActiveWorkbook.Colors(1)
ActiveWorkbook.Colors(1) = lngO
End If
End If
SelectColor = lngResult
End Function
und ersetze den Code im Klassenmodul clsButton durch diesen
Public WithEvents Button As MSForms.CommandButton
Private Sub Button_Click()
Dim c As Range
Dim a
a = SelectColor(ActiveCell.Interior.Color)
For Each c In Selection
c.Interior.Color = a
Next
frmFarben.Hide
End Sub
jetzt wird direkt das erweiterte Farbfenster aufgerufen.
Farbwert = Basiswert + TaS * (255 - Basiswert)
ergibt sich für die Rückrechnung eigentlich folgende Formel
Basiswert = (Farbwert- 255*TaS)/ (-TaS+1)
das paßt aber leider nicht immer.Function lesen(Index As Long) As String
Dim Ordner As String
Dim Liste As String
Dim myarr(42) As Variant
Dim myarr2 As Variant
Dim Text As String
Dim i As Long
Dim k As Long
Dim fo As Object
Dim fi As Object
Dim fso As Object
ReDim myarr2(2)
myarr2(0) = Array("Adjacency", "Alte Farben", "Angles", "Apex", "Apothecary", "Aspect", "Austin" _
, "Black Tie", "Civic", "Clarity", "Composite", "Concourse", "Couture", "Elemental", "Equity", "Essential", "Executive", "Flow", "Foundry", "Grayscale", "Grid", "Hardcover", "Horizon", "Median", "Metro", "Module", "Newsprint", "Opulent", "Oriel", "Origin", "Paper", "Perspective", "Pushpin", "Slipstream", "Solstice", "Standard", "Technic", "Thatch", "Trek", "Urban", "Verve", "Waveform")
myarr2(1) = Array("Nähe", "Alte Farben", "Winkel", "Ananke", "Apotheke", "Ganymed", "Austin", " _
Smoking", "Cronus", "Klarheit", "Zusammengesetzt", "Deimos", "Couture", "Elementar", "Dactylos", "Essenz", "Executive", "Hyperion", "Phoebe", "Graustufe", "Raster", "Hardcover", "Horizont", "Galathea", "Iapetus", "Modul", "Zeitungspapier", "Lysithea", "Nereus", "Okeanos", "Papier", "Perspective", "Pin", "Slipstream", "Nyad", "Larissa", "Haemera", "Stroh", "Metis", "Rhea", "Telesto", "Wellenform")
Ordner = "c:\Program Files\Microsoft Office\Document Themes 14\Theme Colors\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fo = fso.GetFolder(Ordner)
i = 0
For Each fi In fo.Files
myarr(i) = Left(fi.Name, Len(fi.Name) - 4)
i = i + 1
Next
lesen = myarr(Index - 1)
For k = LBound(myarr2(0)) To UBound(myarr2(0))
If myarr2(0)(k) = lesen Then Text = myarr2(1)(k)
Next
Dateiname = lesen & ".xml"
Dateipfad = Ordner & Dateiname
lesen = Text
End Function
soll in der Tabelle die alle Colorthemenfarben anzeigt auch der Colorthemenauswahlname erscheinen, dann folgenden Code benutzen.Public zeile As Long
Public datname As String
Public datpfad As String
Sub Themen()
Dim Ordner As String
Dim Anzahl As Long
Dim Anzahlxml
Dim Liste As String
Dim i
Dim fo As Object
Dim fi As Object
Dim fso As Object
Ordner = "c:\Program Files\Microsoft Office\Document Themes 14\Theme Colors\"
zeile = 3
Set fso = CreateObject("Scripting.FileSystemObject")
Set fo = fso.GetFolder(Ordner)
For Each fi In fo.Files
Anzahl = Anzahl + 1
datname = (fi.Name) 'LCase
If Right(datname, 4) = ".xml" Then
Anzahlxml = Anzahlxml + 1
Liste = Liste & Left(fi.Name, Len(fi.Name) - 4) & Chr(13)
datpfad = Ordner & datname
Call Schreiben
zeile = zeile + 7
End If
Next
ActiveWorkbook.Theme.ThemeColorScheme.Load ("C:\Program Files\Microsoft Office\Document Themes _
14\Theme Colors\Standard.xml")
End Sub
Sub Schreiben()
Dim i
Dim k
Dim x
Dim z
Dim Text As String
Dim myarr2 As Variant
Dim arr
ReDim arr(1 To 5)
arr(1) = Array(-0.049989319, 0.499984741, -0.99948119, 0.799981689, 0.799981689, 0.799981689, _
0.799981689, 0.799981689, 0.799981689, 0.799981689, 0.799981689, 0.799981689)
arr(2) = Array(-0.149967956, 0.349986267, -0.249946593, 0.599963378, 0.599963378, 0. _
599963378, 0.599963378, 0.599963378, 0.599963378, 0.599963378, 0.599963378, 0.599963378)
arr(3) = Array(-0.249946593, 0.249946593, -0.499984741, 0.399945067, 0.399945067, 0. _
399945067, 0.399945067, 0.399945067, 0.399945067, 0.399945067, 0.399945067, 0.399945067)
arr(4) = Array(-0.349986267, 0.149967956, -0.749961852, -0.249946593, -0.249946593, -0. _
249946593, -0.249946593, -0.249946593, -0.249946593, -0.249946593, -0.249946593, -0.249946593)
arr(5) = Array(-0.499984741, 0.049989319, -0.899960326, -0.499984741, -0.499984741, -0. _
499984741, -0.499984741, -0.499984741, -0.499984741, -0.499984741, -0.499984741, -0.499984741)
ReDim myarr2(2)
myarr2(0) = Array("Adjacency", "Alte Farben", "Angles", "Apex", "Apothecary", "Aspect", "Austin" _
, "Black Tie", "Civic", "Clarity", "Composite", "Concourse", "Couture", "Elemental", "Equity", "Essential", "Executive", "Flow", "Foundry", "Grayscale", "Grid", "Hardcover", "Horizon", "Median", "Metro", "Module", "Newsprint", "Opulent", "Oriel", "Origin", "Paper", "Perspective", "Pushpin", "Slipstream", "Solstice", "Standard", "Technic", "Thatch", "Trek", "Urban", "Verve", "Waveform")
myarr2(1) = Array("Nähe", "Alte Farben", "Winkel", "Ananke", "Apotheke", "Ganymed", "Austin", " _
Smoking", "Cronus", "Klarheit", "Zusammengesetzt", "Deimos", "Couture", "Elementar", "Dactylos", "Essenz", "Executive", "Hyperion", "Phoebe", "Graustufe", "Raster", "Hardcover", "Horizont", "Galathea", "Iapetus", "Modul", "Zeitungspapier", "Lysithea", "Nereus", "Okeanos", "Papier", "Perspective", "Pin", "Slipstream", "Nyad", "Larissa", "Haemera", "Stroh", "Metis", "Rhea", "Telesto", "Wellenform")
ActiveWorkbook.Theme.ThemeColorScheme.Load (datpfad)
z = Left(datname, Len(datname) - 4)
For k = LBound(myarr2(0)) To UBound(myarr2(0))
If myarr2(0)(k) = z Then Text = myarr2(1)(k)
Next
With Worksheets(1)
.Cells(zeile, 1).Value = Left(datname, Len(datname) - 4)
.Cells(zeile, 2).Value = Text
.Cells(zeile, 3).Value = ThisWorkbook.Theme.ThemeColorScheme.Colors(2)
.Cells(zeile, 3).Interior.Color = .Cells(zeile, 3).Value
.Cells(zeile, 4).Value = ThisWorkbook.Theme.ThemeColorScheme.Colors(1)
.Cells(zeile, 4).Interior.Color = .Cells(zeile, 4).Value
.Cells(zeile, 5).Value = ThisWorkbook.Theme.ThemeColorScheme.Colors(4)
.Cells(zeile, 5).Interior.Color = .Cells(zeile, 5).Value
.Cells(zeile, 6).Value = ThisWorkbook.Theme.ThemeColorScheme.Colors(3)
.Cells(zeile, 6).Interior.Color = .Cells(zeile, 6).Value
For i = 7 To 14
.Cells(zeile, i).Interior.Color = ThisWorkbook.Theme.ThemeColorScheme.Colors(i - 2) 'Colors( _
x)
.Cells(zeile, i).Value = .Cells(zeile, i).Interior.Color
Next i
k = zeile + 1
Cells(k, 3).Resize(UBound(arr, 1), UBound(arr(1), 1) + 1) = _
WorksheetFunction.Transpose(WorksheetFunction.Transpose(arr))
For x = k To k + 4
For i = 3 To 14
.Cells(x, i).Interior.Color = .Cells(zeile, i).Value
.Cells(x, i).Interior.TintAndShade = .Cells(x, i).Value
.Cells(x, i).Value = Col(.Cells(zeile, i).Value, .Cells(x, i).Value)
Next
Next
End With
End Sub
@LucVorbereitung der UserForm:
frmFarben
hinzu.BackColor
auf Rot.Code für die UserForm:
Private Sub Image1_Click()
frmFarben.Hide
End Sub
Private Sub UserForm_Initialize()
Call Farbensetzen
End Sub
Farbensetzen-Prozedur:
ActiveWorkbook.Theme.ThemeColorScheme.Load
zu laden:Sub Farbensetzen()
' Hier folgt der Code, um die Farben zu befüllen
End Sub
Klassenmodule hinzufügen:
clsButton
und clsLabel
um.clsButton
den Code für das Button-Click-Ereignis ein:Public WithEvents Button As MSForms.CommandButton
Private Sub Button_Click()
' Hier folgt der Code für das Button-Klick-Ereignis
End Sub
Farbdialog erstellen:
SelectColor
hinzu, um einen Farb-Dialog zu öffnen, wo der Benutzer eine Farbe auswählen kann.Testen der UserForm:
Problem: Die Schrift in den TextBoxen wird nicht fett angezeigt.
Font.Bold
korrekt gesetzt ist.Problem: UserForm zeigt keine Farben an.
activeworkbook.theme.themecolorscheme.load
geladen werden.excel vba themecolor list
verwenden, um eine Liste von Farben zu generieren, die in einem Dropdown-Menü angezeigt werden kann.ral farben rgb tabelle excel
, um die RGB-Werte der RAL-Farben in dein Programm zu integrieren.excel vba themecolor
-Liste auswählt und auf die aktive Zelle anwendet..themecolor vba
-Funktionalität, um benutzerdefinierte Farbpaletten für deine Projekte zu erstellen.interior.themecolor
-Eigenschaft für die Formatierung von Zellen in Excel verwendest, um die Farben direkt anzuwenden.RAL 5003 RGB
-Farben, um deine Designs ansprechender zu gestalten.1. Wie kann ich benutzerdefinierte Farben in Excel VBA verwenden? Du kannst benutzerdefinierte Farben über den Farbdialog wählen und die RGB-Werte in deinem VBA-Code speichern.
2. Was sind die häufigsten Fehler beim Arbeiten mit Themecolor in VBA? Häufige Fehler sind das Vergessen, die entsprechenden Module zu laden oder die falschen Eigenschaften für die Farbanwendung zu verwenden.
3. Gibt es eine Liste von RAL-Farben für Excel?
Ja, du kannst eine ral farben rgb tabelle excel
verwenden, um die Standard-RAL-Farben in deine Excel-Projekte zu integrieren.
Die erweiterte Suchfunktion hilft dir, gezielt die besten Antworten zu finden
Suche nach den besten AntwortenEntdecke unsere meistgeklickten Beiträge in der Google Suche
Top 100 Threads jetzt ansehen