IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VBA Word Discussion :

Action en pied-de-page [WD-2007]


Sujet :

VBA Word

  1. #1
    Kynoq
    Invité(e)
    Par défaut Action en pied-de-page
    Bonjour,

    Dans le cadre de mon travail, on m'a demandé de créer une macro sur Word 2007 permettant d'insérer un pied-de-page. Celui-ci est sous forme de tableau avec des images et du texte à l’intérieur.

    N'ayant jamais fais de macro, j'ai pu trouver quelques bouts de code par-ci par-là pour réussir à créer ce tableau. Cependant, l'action crée le tableau dans la page et non pas dans le pied-de-page.

    Voici le code que j'ai mis dans la macro (Il est sans doute pas du tout propre et contient sûrement des bouts inutiles, mais comme dis précédemment, c'est la première fois que j'en fais et j'ai dû piocher un peu partout sur le web) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    Sub Bas_de_page()
    '
    ' Bas_de_page Macro
    '
    '
     
        Dim WordApp As Word.Application
        Dim WordDoc As Word.Document
     
        Set myRange = ActiveDocument.Range(0, 0)
        ActiveDocument.Tables.Add Range:=myRange, NumRows:=1, NumColumns:=5
     
        'insérer une image dans la 3eme Cellule de la 2eme colonne (dans le 1er tableau d'un document Word )
       myRange.Tables(1).Columns(1).Cells(1).Range.InlineShapes.AddPicture _
                FileName:="H:\Modèles\Logos\Zewo.png", linkToFile:=False, saveWithDocument:=True
     
        With ActiveDocument.InlineShapes(ActiveDocument.InlineShapes.Count)
            .Height = 30   'redimensionne hauteur image
            .Width = 30    'redimensionne largeur image
        End With
     
        'insérer une image dans la 3eme Cellule de la 2eme colonne (dans le 1er tableau d'un document Word )
       myRange.Tables(1).Columns(2).Cells(1).Range.InlineShapes.AddPicture _
                FileName:="H:\Modèles\Logos\Eduqua.png", linkToFile:=False, saveWithDocument:=True
     
        With ActiveDocument.InlineShapes(ActiveDocument.InlineShapes.Count)
            .Height = 23   'redimensionne hauteur image
            .Width = 75    'redimensionne largeur image
            .PictureFormat.ColorType = msoPictureGrayscale
        End With
     
        With Selection.Tables(1)
            If .Style <> "Grille du tableau" Then
                .Style = "Grille du tableau"
            End If
            .ApplyStyleHeadingRows = True
            .ApplyStyleLastRow = True
            .ApplyStyleFirstColumn = True
            .ApplyStyleLastColumn = True
        End With
     
            'Insertion des textes de la colone 2
     
        Selection.MoveRight Unit:=wdCell
        Selection.MoveRight Unit:=wdCell
        Selection.Font.Size = 8
        Selection.Font.Name = "Arial"
        Selection.Font.Bold = True
        Selection.TypeText Text:="Site de la Chaux-de-Fonds"
        Selection.Font.Bold = False
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
        Selection.TypeParagraph
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="Rue de la Paix 71 / cp 299"
        Selection.TypeParagraph
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="2300 La Chaux-de-Fonds"
        Selection.TypeParagraph
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="Téléphone 032 886 88 60"
        Selection.TypeParagraph
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="Téléfax 032 886 82 40"
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
            'Insertion des textes de la colonne 3
     
        Selection.MoveRight Unit:=wdCell
        Selection.Font.Size = 8
        Selection.Font.Name = "Arial"
        Selection.Font.Bold = True
        Selection.TypeText Text:="Site de Neuchâtel"
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
        Selection.TypeParagraph
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="Avenue du Premier-Mars 2a"
        Selection.TypeParagraph
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="2000 Neuchâtel"
        Selection.TypeParagraph
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="Téléphone 032 886 88 60"
        Selection.TypeParagraph
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="Téléfax 032 886 82 67"
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
     
            'Insertion des textes de la colone 4
     
        Selection.MoveRight Unit:=wdCell
        Selection.Font.Size = 8
        Selection.Font.Name = "Arial"
        Selection.Font.Bold = True
        Selection.TypeText Text:="Croix-Rouge suisse"
        Selection.Font.Bold = False
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
        Selection.TypeParagraph
     
        Selection.Font.Size = 8
        Selection.Font.Bold = True
        Selection.TypeText Text:="Canton de Neuchâtel"
        Selection.TypeParagraph
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="contact@croix-rouge-ne.ch"
        Selection.TypeParagraph
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="www.croix-rouge-ne.ch"
        Selection.TypeParagraph
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        Selection.Font.Size = 8
        Selection.Font.Bold = False
        Selection.TypeText Text:="CCP 20-1504-8"
        Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
     
        'Ajustement de la taille du tableau en fonction de son contenu
        ActiveDocument.Tables(1).AutoFitBehavior _
        wdAutoFitContent
     
        'Retrait de certaine bordures
        With Selection.Tables(1)
        .Borders(wdBorderTop).LineStyle = wdLineStyleNone
        .Borders(wdBorderBottom).LineStyle = wdLineStyleNone
        .Borders(wdBorderLeft).LineStyle = wdLineStyleNone
        End With
     
        Selection.MoveLeft Unit:=wdCell
        Selection.MoveLeft Unit:=wdCell
        Selection.MoveLeft Unit:=wdCell
        Selection.MoveLeft Unit:=wdCell
        Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone 'supprime la ligne de droite
     
        End Sub
    J'aimerais donc, que cette action ne se réalise non pas sur la page, mais dans le pied-de-page. Connaissez-vous un moyen de faire ça ?

    Peut-être avec "ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter" ? J'avoue être un peu perdu et pourtant j'ai essayé plus d'une fois...

    Je ne sais pas si mes explications sont claires, cependant je suis à disposition au cas où j'aurais oublié des détails importants.

    Je vous remercie infiniement d'avance !

    Kynoq
    Dernière modification par Obsidian ; 20/06/2016 à 01h10.

  2. #2
    Rédacteur/Modérateur

    Avatar de Heureux-oli
    Homme Profil pro
    Contrôleur d'industrie
    Inscrit en
    Février 2006
    Messages
    21 087
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 59
    Localisation : Belgique

    Informations professionnelles :
    Activité : Contrôleur d'industrie
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Février 2006
    Messages : 21 087
    Points : 42 926
    Points
    42 926
    Par défaut
    Salut,

    Tu ne dois pas passer par un changement de fenêtre, il faut agir directement dans le pied de page.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Activedocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.....
    J'ai pas encore de décodeur, alors, postez en clair ! Comment mettre une balise de code ?
    Débutez en VBA

    Mes articles


    Dans un MP, vous pouvez me dire que je suis beau, ... mais si c'est une question technique je ne la lis pas ! Vous êtes prévenus !

  3. #3
    Kynoq
    Invité(e)
    Par défaut Merci !
    J'ai réussi à trouver un code qui correspond exactement à ma demande et en utilisant justement ce que tu m'as indiqué.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    'adds table in the footer
    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables.Add _
                                            Range:=ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range, _
                                            NumRows:=1, _
                                            NumColumns:=3
     
    'fills the first cell  
    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 1).Select
     
    Selection.TypeText Text:="streetname 166 ..."
    Selection.TypeParagraph
    Selection.TypeText Text:="T 012 ..."
    Selection.TypeParagraph
    Selection.Style = ActiveDocument.Styles("Hyperlink")
    Selection.TypeText Text:="www.website.com"
    Selection.TypeParagraph
     
    'fills the second cell
    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 2).Select
     
    Selection.Font.Size = 6
    Selection.TypeText Text:="Other det ..."
    Selection.TypeParagraph
    Selection.TypeText Text:="Juridical ..."
    Selection.TypeParagraph
     
    'fills the third cell with the picture and change its size
    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1).Cell(1, 3).Select
     
    Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
    Selection.InlineShapes.AddPicture FileName:="C:\image001.jpg"
     
    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.InlineShapes(1).Height = 27.79
    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.InlineShapes(1).Width = 27.79
    Fait par CiernyPeter sur http://forums.codeguru.com/printthread.php?t=294374


    Merci beaucoup !

    Kynoq

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [9]Totalisation par pied de page
    Par _tinos dans le forum SAP Crystal Reports
    Réponses: 12
    Dernier message: 23/03/2007, 11h04
  2. [CR & VB.NET] Pb impression pied de page
    Par arno2000 dans le forum SDK
    Réponses: 2
    Dernier message: 07/03/2005, 09h13
  3. [CR9] Pied de page 2
    Par Machuet dans le forum SAP Crystal Reports
    Réponses: 3
    Dernier message: 12/07/2004, 09h17
  4. [VB6] [Datareport] Heure d'impression ds pied de page
    Par oazar dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 03/10/2002, 10h11
  5. [CR] entête et pied sur page 1/B de matrice
    Par chloe.j3 dans le forum SAP Crystal Reports
    Réponses: 2
    Dernier message: 04/09/2002, 12h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo