Home > Software design >  Adding a table in a word footer using excel VBA
Adding a table in a word footer using excel VBA

Time:04-06

I want to add a table in a footer of .docx using excel vba.

At the end the macro will change some markers in my .docx, and the footer can be different. thats why i want to use excel.

Here is my code but i have a 91 error, idk why. any advice is welcome :)

Option Explicit

Private Sub test()

    
'Déclaration des variables
    Dim MaFeuille As Worksheet
    Dim word_app As Word.Application
    Dim word_fichier As Word.Document
    Dim tbl As Word.Table
    Dim fichier As String

    
'On récupère le fichier test
    
    fichier = ActiveWorkbook.Path & "\" & "test.docx"

'Ouverture de word
        Set word_app = CreateObject("Word.Application")
        With word_app
            .Visible = True
            .WindowState = 1
        End With
        
'Test tableau bas de page
    With word_fichier
            Set tbl = .Tables.Add(word_fichier.Sections(1).Footers(wdHeaderFooterPrimary).Range, 2, 2)
    End With
    
    With tbl
        .Cell(1, 1).Range.Text = "test"
    End With
        
End Sub

CodePudding user response:

wdHeaderFooterPrimary is a Word constant (see enter image description here

Instead of this (that i want, i used paint to do that) : enter image description here

  • Related