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
| ' sous VBE Menu Outils | Références
' Cocher Acrobat Distiller
Sub Tst_Adobe_PDF_03()
Dim sNomFichierPS As String
Dim sNomFichierPDF As String
Dim sNomFichierLOG As String
Dim PDFDist As PdfDistiller
Dim PrinterDefault As String
' Sur un PC "Personnel" : a priori choix libre du Nom
' et de l'emplacement du fichier de sortie
'
' Sur un PC "Entreprise" :
' Il faut être logué en Administrateur ou en
' Avoir les droits pour utiliser Distiller
' Les chemins PS PDF LOG devront être de la forme :
' "C:\Documents and Settings\UserName\.....\....."
' Si l'on a plusieurs imprimantes il faut :
' Sélectionner l'imprimante virtuelle Adobe PDF tout en conservant
' trace de l'imprimante utilisée par défaut
' Le N° de port réseau NeXY varie suivant le PC sur lequel la macro tourne
PrinterDefault = Application.ActivePrinter
Application.ActivePrinter = Imprimante_AdobePDF
sNomFichierPS = ThisWorkbook.Path & "\" & "Essai_AdobbePDF.ps"
sNomFichierPDF = ThisWorkbook.Path & "\" & "Essai_AdobbePDF.pdf"
sNomFichierLOG = ThisWorkbook.Path & "\" & "Essai_AdobbePDF.log"
' Impression d'une zone nommée
ActiveSheet.Range("Zone").PrintOut Copies:=1, Preview:=False, _
ActivePrinter:="Acrobat PDF", PrintToFile:=True, _
Collate:=True, PrToFilename:=sNomFichierPS
Set PDFDist = New PdfDistiller
PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, ""
Set PDFDist = Nothing
Kill sNomFichierPS
Kill sNomFichierLOG
Application.ActivePrinter = PrinterDefault
End Sub
Private Function Imprimante_AdobePDF() As String
Dim i As Integer
Dim NomPortReseau As String
' 11 imprimantes réseau
For i = 0 To 10
If i < 10 Then
NomPortReseau = "Adobe PDF sur Ne0" & i & ":"
Else
NomPortReseau = "Adobe PDF sur Ne" & i & ":"
End If
On Error Resume Next
Application.ActivePrinter = NomPortReseau
If ActivePrinter = NomPortReseau Then
Exit For
End If
Next i
Imprimante_AdobePDF = NomPortReseau
End Function |