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
|
Option Explicit
Sub test()
'Déclaration des variables
Dim I As Integer
Dim Fichier As String
Dim MaFeuille As Worksheet
Dim ListeBordures As Variant
Dim word_app As Word.Application, word_fichier As Word.Document, tbl As Word.Table, rngCell As Word.Range
'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
Set word_fichier = .Documents.Open(Fichier)
End With
'Test tableau bas de page
With word_fichier
Set tbl = .Tables.Add(.Sections(1).Footers(wdHeaderFooterPrimary).Range, 1, 1, wdWord8TableBehavior)
ListeBordures = Array(-1, -2, -3, -4)
With tbl
.Cell(1, 1).Range.Text = "test"
.Rows.HorizontalPosition = InchesToPoints(1)
.Rows.VerticalPosition = InchesToPoints(-2)
.Columns(1).SetWidth ColumnWidth:=310.7, RulerStyle:=1
For I = LBound(ListeBordures) To UBound(ListeBordures)
With .Borders(ListeBordures(I))
.LineStyle = wdLineStyleSingle
.LineWidth = wdLineWidth225pt
.Color = RGB(255, 0, 0)
End With
Next I
End With
End With
Set tbl = Nothing: Set word_fichier = Nothing: Set word_app = Nothing
End Sub |
Partager