RTBtoHTML




Public Function RichToHtml(ByRef rich As RichTextBox) _
As String
Dim mstr As String
Dim x As Integer
Dim y As Integer
x = Len(rich.Text)
Dim bold As Boolean
Dim italic As Boolean
Dim underlined As Boolean
rich.SelStart = 0
rich.SelLength = x
mstr = ""
For y = 0 To x
rich.SelStart = y
rich.SelLength = 1
'controllo grassetto

If rich.SelBold Then
If bold = False Then
bold = True
mstr = mstr & "<strong>"
End If
End If
If rich.SelBold = False Then
If bold = True Then
bold = False
mstr = mstr & "</strong>"
End If
End If
'Controllo corsivo

If rich.SelItalic = True Then
If italic = False Then
italic = True
mstr = mstr & "<em>"
End If
End If
If rich.SelItalic = False Then
If italic = True Then
italic = False
mstr = mstr & "</em>"
End If
End If
'controllo sottolineato

If rich.SelUnderline = True Then
If underlined = False Then
underlined = True
mstr = mstr & "<u>"
End If
End If
If rich.SelUnderline = False Then
If underlined = True Then
underlined = False
mstr = mstr & "</u>"
End If
End If
mstr = mstr & rich.SelText
'controllo invio

If Mid(rich.Text, y + 1, 2) = Chr(13) & Chr(10) _
Then mstr = mstr & "<br>"
Next
If italic Then mstr = mstr & "</em>"
If underlined Then mstr = mstr & "</u>"
If bold Then mstr = mstr & "</strong>"
RichToHtml = mstr
End Function











( rtbtohtml.html )- by Paolo Puglisi - Modifica del 17/12/2023