Sub ajusteComment()
Dim pl As Range, c As Range
Set pl = Cells.SpecialCells(xlCellTypeComments)
If Not pl Is Nothing Then
Application.ScreenUpdating = False
For Each c In pl
c.Comment.Text decoupCh(c.Comment.Text, 50)
c.Comment.Shape.TextFrame.AutoSize = True
With c.Comment.Shape
.Top = c.Top + 2
.Left = c.Offset(, 1).Left + 2
End With
Next c
End If
End Sub
Function decoupCh(ch As String, lMax As Long, Optional suppVbLF = False) As String
Dim pos As Long, tmp, i As Long
'insère chr(10) tous les x caractères, sans couper les mots
If ch <> "" And InStr(ch, " ") > 0 Then
If suppVbLF Then ch = Replace(ch, vbLf, " ")
tmp = Split(ch, vbLf)
For i = 0 To UBound(tmp)
If tmp(i) <> "" Then
pos = lMax + 1
Do
pos = InStrRev(tmp(i), " ", pos)
If pos = 0 Then Exit Do
Mid(tmp(i), pos, 1) = vbLf
pos = pos + lMax + 1
Loop Until pos >= Len(tmp(i))
End If
Next i
End If
decoupCh = Join(tmp, vbLf)
End Function