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
| Sub CommandButton1_Click()
'nécéssite d'activer la référence Microsoft Word xx.x Object Library
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim Fichier As String
Dim i As Byte
'Definition du fichier
Fichier = "E:\Mes documents\TEST MACRO\Doctype.doc"
'ouvre session word
Set WordApp = CreateObject("word.application")
'ouvre document Word
Set WordDoc = WordApp.Documents.Open(Fichier)
'word masqué pendant l'operation
WordApp.Visible = False
'les signets du document Word sont nommés Signet
WordDoc.Bookmarks("SignetDate").Range.Text = Format(Now, "dd/mm/yyyy")
WordDoc.Bookmarks("Prénom").Range.Text = Sheets("Feuil1").Range("B2").Value
'affiche le document Word
WordApp.Visible = True
'Sauvegarde en PDF
WordDoc.ExportAsFixedFormat Type:=xlTypePDF, Filename:="E:\Mes documents\TEST MACRO\Doc.pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub |
Partager