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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| Option Explicit
Private Declare Function SHCreateDirectoryEx Lib "Shell32.dll" Alias "SHCreateDirectoryExA" _
(ByVal hwnd As Long, _
ByVal pszPath As String, _
ByVal lngsec As Long) As Long
Private Function CreationDossier(sDossier) As Long
Dim Rep As Long
Rep = SHCreateDirectoryEx(0&, sDossier, 0&)
End Function
Sub Decoupage_Acrobat_PDF()
Dim i As Long, iNumPage As Long, FSO As Object
Dim sDossier As String, sNomDossier As String
Dim sNomDoc As String, iNbPages As Long
Dim sPrinter As String, sNomFichierPS As String, sNomFichierPDF As String, sNomFichierLOG As String
Dim PDFDist As PdfDistiller
Application.ScreenUpdating = False
sNomDossier = "Charcuterie_PDF"
sDossier = ThisDocument.Path & "\" & sNomDossier
sPrinter = ActivePrinter
ActivePrinter = "Adobe PDF"
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FolderExists(sDossier) Then FSO.DeleteFolder sDossier, True
sNomDoc = FSO.GetBaseName(ThisDocument.Name)
Set FSO = Nothing
CreationDossier sDossier
Application.Browser.Target = wdBrowsePage
iNbPages = ActiveDocument.BuiltInDocumentProperties("Number of Pages")
iNumPage = 0
For i = 1 To iNbPages
ActiveDocument.Bookmarks("\page").Range.Copy
Documents.Add
Selection.Paste
Selection.TypeBackspace
iNumPage = iNumPage + 1
sNomFichierPS = sDossier & "\" & sNomDoc & "_" & Format(iNumPage, "00000") & ".ps"
sNomFichierPDF = sDossier & "\" & sNomDoc & "_" & Format(iNumPage, "00000") & ".pdf"
sNomFichierLOG = sDossier & "\" & sNomDoc & "_" & Format(iNumPage, "00000") & ".log"
Application.PrintOut outputFilename:=sNomFichierPS, PrintToFile:=True, Background:=False, Range:=wdPrintCurrentPage
ActiveDocument.Close SaveChanges:=False
Set PDFDist = New PdfDistiller
PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, ""
Set PDFDist = Nothing
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(sNomFichierPS) Then FSO.DeleteFile (sNomFichierPS), True
If FSO.FileExists(sNomFichierLOG) Then FSO.DeleteFile (sNomFichierLOG), True
Set FSO = Nothing
Application.Browser.Next
Next i
ActivePrinter = sPrinter
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Application.ScreenUpdating = True
End Sub |
Partager