Bordure et alignement dans un tableau lors d'un publipostage sur word à partir d

Résolu
cyrilou421 Messages postés 7 Date d'inscription lundi 29 octobre 2007 Statut Membre Dernière intervention 8 janvier 2014 - 3 nov. 2007 à 15:30
cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 - 3 nov. 2007 à 18:19
Bonjour,

Dans mon application, j'effectue un publipostage sur word en vue d'imprimer ou d'enregistrer le document.
Dans mon publipostage je dois mettre un tableau.
Mon code fonctionne. Mais j'aurais aimé configurer les bordures du tableau (car actuellement il n'y en a aucune) et j'aurais aimé configurer aussi l'alignement du texte dans les cellules dans le sens vertical.

Si quelqu'un peut m'aider, merci d'avance.

Voici mon code :



Private Sub publipostage_envoi()
Dim reponse
Dim WordApp As Application, WordDoc, Cadre1 As Range, Cadre2 As Range
        Set WordApp = CreateObject("word.application")
        WordApp.Application.Visible = False
        Set WordDoc = WordApp.Documents.Open("" & App.Path & "\doc.doc")
        Set Cadre1 = WordDoc.Range(Start:=0, End:=0)
        Cadre1.InsertAfter ("Titre" & vbCrLf)
        Cadre1.Bold = True
        Cadre1.Underline = True
        Cadre1.Font.Name = "Arial"
        Cadre1.Font.Size = 16
        Cadre1.ParagraphFormat.Alignment = 1
        Set Cadre2 = WordDoc.Range(Start:=6, End:=6)
        With WordDoc
            .Tables.Add Range:=Cadre2, NumRows:=2, NumColumns:=3
            .Tables(1).Cell(1, 1).Range.Text = "Horaires :"
            .Tables(1).Cell(1, 1).Range.Bold = True
            .Tables(1).Cell(1, 1).Range.Underline = False
            .Tables(1).Cell(1, 1).Range.Font.Name = "arial"
            .Tables(1).Cell(1, 1).Range.Font.Size = "9"
            .Tables(1).Cell(1, 1).Range.ParagraphFormat.Alignment = 1
            .Tables(1).Cell(1, 2).Range.Text = "Discipline :"
            .Tables(1).Cell(1, 2).Range.Bold = True
            .Tables(1).Cell(1, 2).Range.Underline = False
            .Tables(1).Cell(1, 2).Range.Font.Name = "arial"
            .Tables(1).Cell(1, 2).Range.Font.Size = "9"
            .Tables(1).Cell(1, 3).Range.Text = "Domaine :"
            .Tables(1).Cell(1, 3).Range.Bold = True
            .Tables(1).Cell(1, 3).Range.Underline = False
            .Tables(1).Cell(1, 3).Range.Font.Name = "arial"
            .Tables(1).Cell(1, 3).Range.Font.Size = "9"
        End With
        reponse = MsgBox("Voulez-vous enregistrer le fichier?", vbExclamation + vbMsgBoxSetForeground + vbDefaultButton1 + vbYesNo, "Enregistrer?")
        If reponse = vbYes Then
            WordDoc.SaveAs ("" & App.Path & "\fichier.doc")
        End If
        If reponse = vbNo Then
        End If
        WordDoc.Close
        WordApp.Quit
        Set WordDoc = Nothing
        Set WordApp = Nothing
End Sub

1 réponse

cs_Jack Messages postés 14006 Date d'inscription samedi 29 décembre 2001 Statut Modérateur Dernière intervention 28 août 2015 79
3 nov. 2007 à 18:19
Salut
Comme toujours avec Word ou Excel, du moment que tu sais le faire à la main, tu sais le programmer :
- Ouvre un de tes docus Word ainsi généré et enregistre une nouvelle macro.
- Fais tes arrangements de style puis arrête l'enregistrement.
- Va jetter un coup d'oeil dans l'éditeur VB de macro : le code est là.
- Copie-Colle le dans ton projet VB6 en l'arrangeant un peu (nom des objets et paramétrage éventuel)

Vala
Jack, MVP VB
NB : Je ne répondrai pas aux messages privés

<hr />Le savoir est la seule matière qui s'accroit quand on la partage (Socrate)
3
Rejoignez-nous