VBA-Beispiel 134
mail schreiben
mail schreiben

Schriftfarbe per Zufall

Jedes Wort einer Zelle mit zufälliger Schriftfarbe formatieren.
Public Sub SchriftfarbeZufall()
Dim rng As Range
Dim intFarbe As Integer
Dim arr
Dim i As Long, pos As Long

  Set rng = Tabelle1.Range("A1")

  If rng.Value = "" Then
    MsgBox "Kein Text in Zelle.", , ""
    Exit Sub
  End If

  arr = Split(rng.Value)
  Randomize

  For i = 0 To UBound(arr)
    intFarbe = Int((56 * Rnd) + 1)
    rng.Characters(Start:=pos + i, Length:=Len(rng)) _
       .Font.ColorIndex = intFarbe
    pos = pos + Len(arr(i))
  Next i

  Set rng = Nothing
  Erase arr
End Sub

Download:   vba134.zip