créer un format pdf, en vb sous excel 2000 xlTypePDF est inutilisable

Goufra

XLDnaute Occasionnel
Bonsoir,

Je vous remercie par avance pour votre aide.

Sous excel 2000 impossible d'utiliser le code :

z = "c:\recep\" & numero & " - " & titre & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=z​

Il ressort : erreur de compilation variable : (xlTypePDF) non définie.

Comment palier cet inconvénient ?
Le but est de sauvegarder une plage sous format pdf; sauvegarde dont le nom évolue grâce à une variable.
Bonne soirée à vous
 

Pièces jointes

  • Goufra.xls
    40 KB · Affichages: 51
  • Goufra.xls
    40 KB · Affichages: 51
  • Goufra.xls
    40 KB · Affichages: 56

Staple1600

XLDnaute Barbatruc
Re : créer un format pdf, en vb sous excel 2000 xlTypePDF est inutilisable

Bonsoir à tous


Goufra:
Il faut passer par PDFCreator par exemple.
Tu trouveras dans les archives du forum des fils de discussion expliquant comment faire.
Utilises pour cela la loupe en haut à droite de l'écran.

EDITION: Tu trouveras par exemple ce code de Ken Puls (je te laisse trouver dans quelle discussion sur XLD ce code se trouve)
VB:
Option Explicit
Sub PrintToPDF_Early()
'Author       : Ken Puls ([url=http://www.excelguru.ca]Excelguru Help Site - Welcome[/url])
'Macro Purpose: Print to PDF file using PDFCreator
'   (Download from [url=http://sourceforge.net/projects/pdfcreator/]PDFCreator | Free Business & Enterprise software downloads at SourceForge.net[/url])
'   Designed for early bind, set reference to PDFCreator


    Dim pdfjob As PDFCreator.clsPDFCreator
    Dim sPDFName As String
    Dim sPDFPath As String
    Dim bRestart As Boolean


    '/// Change the output file name here! ///
    sPDFName = "testPDF.pdf"
    sPDFPath = ActiveWorkbook.Path & Application.PathSeparator


    'Check if worksheet is empty and exit if so
    If IsEmpty(ActiveSheet.UsedRange) Then Exit Sub


    'Activate error handling and turn off screen updates
    On Error GoTo EarlyExit
    Application.ScreenUpdating = False
    Set pdfjob = New PDFCreator.clsPDFCreator


    'Check if PDFCreator is already running and attempt to kill the process if so
    Do
        bRestart = False
        Set pdfjob = New PDFCreator.clsPDFCreator
        If pdfjob.cStart("/NoProcessingAtStartup") = False Then
            'PDF Creator is already running.  Kill the existing process
            Shell "taskkill /f /im PDFCreator.exe", vbHide
            DoEvents
            Set pdfjob = Nothing
            bRestart = True
        End If
    Loop Until bRestart = False


    'Assign settings for PDF job
    With pdfjob
        .cOption("UseAutosave") = 1
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = sPDFPath
        .cOption("AutosaveFilename") = sPDFName
        .cOption("AutosaveFormat") = 0    ' 0 = PDF
        .cClearCache
    End With


    'Delete the PDF if it already exists
    If Dir(sPDFPath & sPDFName) = sPDFName Then Kill (sPDFPath & sPDFName)


    'Print the document to PDF
    ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"


    'Wait until the print job has entered the print queue
    Do Until pdfjob.cCountOfPrintjobs = 1
        DoEvents
    Loop
    pdfjob.cPrinterStop = False


    'Wait until the file shows up before closing PDF Creator
    Do
        DoEvents
    Loop Until Dir(sPDFPath & sPDFName) = sPDFName


Cleanup:
    'Release objects and terminate PDFCreator
    Set pdfjob = Nothing
    Shell "taskkill /f /im PDFCreator.exe", vbHide
    On Error GoTo 0
    Application.ScreenUpdating = True
    Exit Sub


EarlyExit:
    'Inform user of error, and go to cleanup section
    MsgBox "There was an error encountered.  PDFCreator has" & vbCrLf & _
           "has been terminated.  Please try again.", _
           vbCritical + vbOKOnly, "Error"
    Resume Cleanup
End Sub
 
Dernière édition:

kiki29

XLDnaute Barbatruc
Re : créer un format pdf, en vb sous excel 2000 xlTypePDF est inutilisable

Salut, attention aux versions de PDFCreator, perso en utilisation actuellement, j'en suis resté à la version 1.2.3 et pas à la dernière 1.5.1 qui pose qqs problèmes.
Autrement le format PDF est intégré en natif à partir d'Office 2007 SP2.
 

Staple1600

XLDnaute Barbatruc
Re : créer un format pdf, en vb sous excel 2000 xlTypePDF est inutilisable

Bonjour kiki29 ;)

J'ai failli mettre en lien ceux de ta signature, mais j'ai cru comprendre que tes procédures utilisent Distiller
(qui est fourni avec Acrobat*)

D'où le code VBA de Ken Puls soumis précédemment.

PS: *: Pas Acrobat Reader, mais l'autre qui lui est plus onéreux ;)
 

kiki29

XLDnaute Barbatruc
Re : créer un format pdf, en vb sous excel 2000 xlTypePDF est inutilisable

Salut, exact en fait dans les en-têtes des exemples concernant PDFCreator le terme PDFCreator est présent, dans ceux concernant Adobe Acrobat Ptofessionnal rien n'est précisé, il y en un concernant Acrobat Reader. Un PDF avec les liens qui éclaicira les choses
 
Dernière édition:

Staple1600

XLDnaute Barbatruc
Re : créer un format pdf, en vb sous excel 2000 xlTypePDF est inutilisable

Bonjour à tous

kiki29
Je viens de lire ton pdf.
Donc (sauf erreur de lecture), il faut bourse délier si on veut exporter une feuille, un classeur en PDF en utilisant Acrobat Pro sur des versions d'Excel inférieure à XL 2010 (avec 2007 il y avait un addin à installer si je me souviens bien)
Goufra voulant faire cela sous Excel 2000 (et s'il veut garder quelques sous pour Noel), Excel+PDFCreator est la piste la plus simple, non ?


PS: Bravo à toi pour cette "exhaustivité pdfienne" ;), (et pour la beauté de tes codes VBA)
 

Goufra

XLDnaute Occasionnel
Re : créer un format pdf, en vb sous excel 2000 xlTypePDF est inutilisable

Bonsoir à vous,

Merci pour votre rapidité et vos explications exhaustives !

Bref j'ai donc dû changer mon fusil d'épaule pour obtenir à l'identique un fichier XLS qui ne comporte que les plages à imprimer.

Ce n'est pas très compliqué, mais c'est plus long ! j'ai donc créé :

- une feuille par plage à imprimer et à sauvegarder, (sans oublier le code pour assurer la mise en page)
- un fichier vers lequel je déplace lesz feuilles concernées.​
Merci encore à vous pour votre aide ... indéflectible.
Bonne soirée
Goufra
 

Discussions similaires

Statistiques des forums

Discussions
312 417
Messages
2 088 251
Membres
103 788
dernier inscrit
yassine arfi