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
| Sub Passage_Excel_Word()
Dim appWord As New Word.Application
Dim docWord As New Word.Document
Dim tableLocation As Object
' Il faut créer un nouveau document Word dans l'application Word
With appWord
.Visible = True
Set docWord = .Documents.Add
.Activate
End With
appWord.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Dim docModele As Template
Set tableLocation = appWord.Selection.Range
Templates.LoadBuildingBlocks ' chargement du template building blocks
' recherche du bon template
For Each docModele In Templates
If docModele.Name = "Building Blocks.dotx" Then
' si trouvé insertion du bloc table des matières
Templates(docModele.FullName).BuildingBlockEntries("Numéros en gras 1").Insert Where:=tableLocation
Exit For
End If
Next
'Enregistrer le document Word
With docWord
.SaveAs ThisWorkbook.Path & "\ca_2003.doc", Allowsubstitutions:=True
'Dans Word Aperçu avant impression du résultat
.PrintPreview
End With
'Réinitialiser l'objet
Set appWord = Nothing
Set docWord = Nothing
End Sub |
Partager