Problème avec Macro VBA Excel 2003 création de fichier pdf avec adobe 9.5 pro

farf2101

XLDnaute Nouveau
Bonjour à vous

J'aurais une question pour vous
Actuellement j'ai un code qui fonctionne très bien pour créer des fichiers pdf à partir d'excel 2003 avec adobe acrobat 6 pro et aussi vs 9 pro mais lorsque j'essaie sur version 9.5 ça gèle et l'ordinateur ne répond plus
Je cherche désèspérément sur le web et je ne trouve rien. Peut-être qu'un bon samaritain d'entre vous pourra m'aider je vous en serais très reconnaissant

Voici le code de la macro que j'utilise Je l'avais trouvée sur le web et adaptée il y a quelques années

MErci à l'avance

Farf2101


' sous VBE Menu Outils | Références
' Cocher Acrobat Distiller

Option Explicit
Dim sNomPortReseau As String

Sub Convert__rapport_tribune_xls_to_pdf()
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, on est logué en
' Administrateur sur son PC
'
' 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
If Imprimante_AdobePDF Then
Application.ActivePrinter = sNomPortReseau
Else
MsgBox "Pas d'imprimante Adobe PDF sur NeXY ", vbOKOnly + vbCritical, "Achtung"
Exit Sub
End If

' Ici le cas d'un PC "Personnel" ""
'MsgBox "joyo10 "
sNomFichierPS = "P:\Dossier de publications (CASIQ)\Site_CASIQ\accueil\rapports journaliers\rapport_La_tribune.ps"
sNomFichierPDF = "P:\Dossier de publications (CASIQ)\Site_CASIQ\accueil\rapports journaliers\rapport_La_tribune.pdf"
sNomFichierLOG = "P:\Dossier de publications (CASIQ)\Site_CASIQ\accueil\rapports journaliers\rapport_La_tribune.log"

' Impression d'une zone nommée
'MsgBox "joyo11 "

Windows("rapport_La_tribune.xls").Activate
'MsgBox "joyo12 "

'Sheets("la tribune").Select
Sheets("la tribune").Activate

'Range("zone_d_impression").Select
'MsgBox "joyo13 "

ActiveSheet.Range("Zone_d_impression").PrintOut Copies:=1, Preview:=False, _
ActivePrinter:=sNomPortReseau, PrintToFile:=True, _
Collate:=True, PrToFilename:=sNomFichierPS
'MsgBox "joyo14 "

Set PDFDist = New PdfDistiller
PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, ""
Set PDFDist = Nothing

'MsgBox "joyo1 "

Kill sNomFichierPS
Kill sNomFichierLOG
'MsgBox "joyo2 "
Application.ActivePrinter = PrinterDefault
'MsgBox "joyo3 "

End Sub

Public Function Imprimante_AdobePDF() As Boolean
Dim i As Long
' 11 imprimantes réseau
Imprimante_AdobePDF = False
'MsgBox "jo1Y ", vbOKOnly + vbCritical, "Achtung"
'MsgBox ActivePrinter
For i = 0 To 10
If i < 10 Then
sNomPortReseau = "Adobe PDF sur Ne0" & i & ":"
'MsgBox "jo2Y ", vbOKOnly + vbCritical, "Achtung"
Else
sNomPortReseau = "Adobe PDF sur Ne" & i & ":"
'MsgBox "jo3Y ", vbOKOnly + vbCritical, "Achtung"
End If
On Error Resume Next
'MsgBox "jo4Y ", vbOKOnly + vbCritical, "Achtung"
Application.ActivePrinter = sNomPortReseau
'MsgBox "jo5Y ", vbOKOnly + vbCritical, "Achtung"
If ActivePrinter = sNomPortReseau Then
'MsgBox ActivePrinter
Imprimante_AdobePDF = True
'MsgBox Imprimante_AdobePDF
Exit For
End If
Next i
'MsgBox ActivePrinter
End Function
 

farf2101

XLDnaute Nouveau
Re : Problème avec Macro VBA Excel 2003 création de fichier pdf avec adobe 9.5 pro

Je sais que mon code bug à cette ligne

ActiveSheet.Range("Zone_d_impression").PrintOut Copies:=1, Preview:=False, _
ActivePrinter:=sNomPortReseau, PrintToFile:=True, _
Collate:=True, PrToFilename:=sNomFichierPS

et j'ai mis cette ligne avant pour sélectionner la bonne zone et la plage de cellule est bel et bien nommé dans mon fichier et fait référence au bon range

'Range("zone_d_impression").Select
 

Discussions similaires

Statistiques des forums

Discussions
311 720
Messages
2 081 897
Membres
101 833
dernier inscrit
sandra25