1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| Sub CréationBalise()
Dim cell As Range
For Each cell In Selection
Dim ColorDefault As Integer
ColorDefault = -4105
Dim d As Integer ' counter
Dim s As String ' tanpom
Dim B As Boolean ' for BOLD
Dim U As Boolean ' for underline
Dim I As Boolean ' for Italic
Dim C As Long ' for Color
C = ColorDefault
s = "<html><body>"
For d = 1 To Len(cell.Value) Step 1
If cell.Characters(d, 1).Font.Bold = True Then ' Gestion Du gras
If B = False Then '
s = s + "<b>" '
B = True '
End If '
End If '
If cell.Characters(d, 1).Font.Bold = False And B = True Then '
s = s + "</b>" '
B = False '
End If '
If cell.Characters(d, 1).Font.Underline = xlUnderlineStyleSingle Then ' Gestion du soulignement
If U = False Then '
s = s + "<u>" '
U = True '
End If '
End If '
If cell.Characters(d, 1).Font.Underline = xlUnderlineStyleNone And U = True Then '
s = s + "</U>" '
U = False '
End If '
If cell.Characters(d, 1).Font.Italic = True Then ' Gestion de l'italique
If I = False Then '
s = s + "<i>" '
I = True '
End If '
End If '
If cell.Characters(d, 1).Font.Italic = False And I = True Then '
s = s + "</i>" '
I = False '
End If '
If cell.Characters(d, 1).Font.ColorIndex <> ColorDefault Then ' Gestion de la couleur
Dim Rouge, Vert, Bleu As Integer
Rouge = Int(cell.Characters(d, 1).Font.ColorIndex Mod 256)
Vert = Int((cell.Characters(d, 1).Font.ColorIndex Mod 65536) / 256)
Bleu = Int(cell.Characters(d, 1).Font.ColorIndex / 65536)
If cell.Characters(d, 1).Font.ColorIndex <> C And C <> ColorDefault Then
s = s + "</font>"
s = s + "<font color=#""" + Format(Hex(Rouge), "##00") + Format(Hex(Vert), "##00") + Format(Hex(Bleu), "##00") + """>"
C = cell.Characters(d, 1).Font.ColorIndex '
ElseIf C = ColorDefault And cell.Characters(d, 1).Font.ColorIndex <> ColorDefault Then
s = s + "<font color=#""" + Format(Hex(Rouge), "##00") + Format(Hex(Vert), "##00") + Format(Hex(Bleu), "##00") + """>"
C = cell.Characters(d, 1).Font.ColorIndex '
End If
End If
If cell.Characters(d, 1).Font.ColorIndex = ColorDefault And C <> ColorDefault Then
s = s + "</font>"
C = ColorDefault
End If '
s = s + Right(Left(cell.Value, d), 1)
Next
If B = True Then
s = s + "</b>"
B = False
End If
If U = True Then
s = s + "</u>"
U = False
End If
If I = True Then
s = s + "</i>"
I = False
End If
If C <> ColorDefault Then '
s = s + "</font>" '
C = ColorDefault '
End If
's = Replace(s, """", """)
's = Replace(s, "&", "&")
' Rétablissement des """, modifiés par la ligne RemplaceCar "&", "&"
's = Replace(s, "&quot", """)
s = Replace(s, "à", "à")
s = Replace(s, "é", "é")
s = Replace(s, "è", "è")
s = Replace(s, "ê", "ê")
s = Replace(s, "î", "î")
s = Replace(s, "ô", "ô")
s = Replace(s, "ù", "ù")
s = Replace(s, vbLf, "</p>")
cell.Value = s + "</body></html>"
Next
End Sub |
Partager