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
| Sub ouvrirDocWord_Impression()
'necesite d'activer la reference Microsoft Word xx.x Object Library (dans menu Outils/References)
Dim appWrd As Word.Application
Dim docWord As Word.Document
Dim Fichier As String
Dim NomFichier As String
Dim Dossier As String
Dim Intpos As Byte
Dim nbPages As Integer
Dim i As Integer
Dossier = ThisWorkbook.Path & "\"
ChDrive Dossier
ChDir Dossier
Fichier = Dir(Dossier & "*.docx")
Do While Len(Fichier) > 0
i = 1
Set appWrd = CreateObject("Word.Application") 'creation session Word
appWrd.Visible = True 'pour que word s'ouvre pendant l'operation
Const wdExportFormatPDF = 17
Const wdExportOptimizeForPrint = 0
Const wdExportAllDocument = 0
Const wdExportDocumentContent = 0
Const wdExportCreateNoBookmarks = 0
Intpos = InStrRev(Fichier, ".")
NomFichier = Left(Fichier, Intpos - 1) & ".pdf"
Set docWord = appWrd.Documents.Open(Dossier & Fichier)
nbPages = appWrd.ActiveWindow.Panes(1).Pages.Count
For i = 1 To nbPages
appWrd.ActiveWindow.LargeScroll down:=1
Application.Wait Time + TimeSerial(0, 0, 2)
i = i + 1
Next
docWord.ExportAsFixedFormat outputFileName:=Dossier & "/" & NomFichier, exportFormat:=wdExportFormatPDF
docWord.Close 'fermer le document Word
appWrd.Quit 'fermer la session Word
Fichier = Dir()
Loop
End Sub |
Partager