AW: Text in Html für Spalte
06.12.2019 17:42:09
volti
Hallo Patrick,
da noch niemand geantwortet hat, versuche ich mich mal daran.
Obwohl es für mich nicht ganz eindeutig ist, was Du möchtest, kann Dir mal mein HTML-Umsetztool geben, welches einen Teil der formatierten Zelle in HTML umsetzt (z.B. für die Verwendung in eMails)
Fett, Kursiv und Unterstrich werden auch innerhalb der Zelle abgearbeitet, Farben, Schrift und Größe derzeit nur für die gesamte Zelle.
Bei Bedarf kannst Du <span> auch in <div> abändern. Abweichend zu deiner Vorgabe werden die Absätze aber nicht mit dem P-Tag abgesetzt sondern mit <br>, sonst gibt das so einen blöden Extraabstand.
Also probiere es aus. Vielleicht ist es ja das, was Du suchst:
Sub FormatiereZelltextinHTML()
'Umsetzung der Zellen in A nach HTML in B
Dim Obj As Range
For Each Obj In Range("$A1:$A308")
If Obj.Value <> "" Then Obj.Offset(0, 1).Value = GetHTML(Obj, False)
Next Obj
End Sub
Function GetHTML(Obj As Range, Optional bHG As Boolean) As String
'Funktion setzt die Parameter/Wert/Formatierung einer Zelle in HTML um
Dim T1 As String, T2 As String, T3 As String, BGC As String, x As Integer
Dim B As String, I As String, U As String, S As String, sText As String
With Obj.Interior
If .ColorIndex <> xlNone And bHG Then
BGC = ";background-color:#" _
& Right("0" & Hex(.Color And vbRed), 2) _
& Right("0" & Hex((.Color And vbGreen) \ &H100), 2) _
& Right("0" & Hex((.Color And vbBlue) \ &H10000), 2)
End If
End With
S = Obj.Font.Size
For x = 1 To Len(Obj.Value)
With Obj.Characters(x, 1).Font
If .FontStyle Like "*Fett*" And B = "" Then B = "</b>": sText = sText & "<b>"
If .FontStyle Like "*Kursiv*" And I = "" Then I = "</i>": sText = sText & "<i>"
If .Underline = xlUnderlineStyleSingle And U = "" Then U = "</u>": sText = sText & "<u>"
If .Underline = xlUnderlineStyleNone And U = "</u>" Then sText = sText & "</u>": U = ""
If Not .FontStyle Like "*Kursiv*" And I = "</i>" Then sText = sText & "</i>": I = ""
If Not .FontStyle Like "*Fett*" And B = "</b>" Then sText = sText & "</b>": B = ""
sText = sText & Mid$(Obj.Value, x, 1)
End With
Next x
If U <> "" Then sText = sText & U
If I <> "" Then sText = sText & I
If B <> "" Then sText = sText & B
With Obj.Font
GetHTML = "<span style='font-size:" & .Size & "pt;font-family:""" _
& .Name & """;color:#" _
& Right("0" & Hex(.Color And vbRed), 2) _
& Right("0" & Hex((.Color And vbGreen) \ &H100), 2) _
& Right("0" & Hex((.Color And vbBlue) \ &H10000), 2) & BGC _
& "'>" & Replace(Replace(sText, vbCrLf, "<br>"), vbLf, "<br>") & "</span>"
End With
End Function
viele Grüße
Karl-Heinz