XL 2016 Ajustement auto colonne / génération mail

Olic78124

XLDnaute Nouveau
Bonjour à toutes et à tous,

Je viens une fois encore avec un problème qui me fait tourner en rond depuis hier.

Je génère des mails contenant un tableau et je n'arrive pas à ajuster la largeur des colonnes de façon automatique (certaines contiennent une date, d'autres des commentaires plus ou moins longs).

Mon code de construction du tableau :
VB:
    strHTML = strHTML & "<TABLE BORDER>"

    For j = 1 To 25 ' Colonnes 1 à 25
        If j < 12 Then
            strHTML = strHTML & "<TD bgcolor='lightgreen'align='center'style='width:100%;white-space:nowrap'><FONT COLOR='black'SIZE=3>" _
                    & Cells(1, j) & "</FONT></TD>"
        ElseIf j < 16 Then
            strHTML = strHTML & "<TD bgcolor='lightskyblue'align='center'style='width:100%;white-space:nowrap'><FONT COLOR='black'SIZE=3>" _
                    & Cells(1, j) & "</FONT></TD>"
        ElseIf j > 19 Then
            If j < 25 Then
                strHTML = strHTML & "<TD bgcolor='LightSteelBlue'align='center'style='width:100%;white-space:nowrap'><FONT COLOR='black'SIZE=3>" _
                        & Cells(1, j) & "</FONT></TD>"
            Else
                strHTML = strHTML & "<TD bgcolor='LightSalmon'align='center'style='width:100%;white-space:nowrap'><FONT COLOR='black'SIZE=3>" _
                        & Cells(1, j) & "</FONT></TD>"
            End If
        End If
    Next j

    DernLigne_lble_env = Range("A" & Rows.Count).End(xlUp).Row  ' Nombre de lignes à prendre en compte

    For liv = 2 To DernLigne_lble_env

            PairImpair = liv And 1
            strHTML = strHTML & "<TR halign='middle'nowrap>"
            For j = 1 To 25 ' Colonnes 1 à 25
                If j < 16 Or j > 19 Then
                    If PairImpair = 0 Then
                        strHTML = strHTML & "<TD bgcolor='white'align='center'style='width:100%;white-space:nowrap'><FONT COLOR='black'SIZE=3>" _
                            & Cells(liv, j) & "</FONT></TD>"
                    Else
                        strHTML = strHTML & "<TD bgcolor='LightGrey'align='center'style='width:100%;white-space:nowrap'><FONT COLOR='black'SIZE=3>" _
                            & Cells(liv, j) & "</FONT></TD>"
                    End If
                End If

                If j = 4 Then
                    If Cells(liv, j) <> "Axx" And Cells(liv, j) <> "Exx" And Cells(liv, j) <> "Stopped" And Cells(liv, j) <> "Estimation charge" Then
                        PresentPxx = DejaPresent(DestPxx, Right(Cells(liv, j), 7))
                        If Not PresentPxx Then
                                DestPxx = DestPxx & Right(Cells(liv, j), 7) & ";"
                        End If
                    End If
                End If
            Next j
            strHTML = strHTML & "</TR>"

    Next liv

    strHTML = strHTML & "</TABLE>"

Je ne connais pas du tout CCS, j'espère ne pas avoir à passer par cette case, mais j'ai lu de-ci de-là que ce serait peut la solution à mon problème.

D'avance merci et bonne journée.
Olivier
 

Statistiques des forums

Discussions
312 370
Messages
2 087 688
Membres
103 639
dernier inscrit
NIEMASAFI