PDF Creator Enregistrer dans deux Dossiers

MuscatMimi

XLDnaute Accro
Bonjour a tous

Avec PDFCreator,je n'arrive pas a trouver la bonne syntaxe
pour enregistrer dans deux dossiers différends
voir ligne en commentaire "ICI" dans OptionButton1 et OptionButton2

Voici Le Code de base de PDFCreator

Code:
[COLOR=BLUE]Private Sub[/COLOR] CommandButton1_Click()
 [COLOR=BLUE]Dim[/COLOR] outName [COLOR=BLUE]As String[/COLOR], i [COLOR=BLUE]As Long[/COLOR]
 [COLOR=GREEN]'**If InStr(1, ActiveWorkbook.Name, ".", vbTextCompare) > 1 Then[/COLOR]
 [COLOR=GREEN]'**outName = Mid(ActiveWorkbook.Name, 1, InStr(1, ActiveWorkbook.Name, ".", vbTextCompare) - 1)[/COLOR]
 [COLOR=GREEN]'**Else[/COLOR]
 [COLOR=BLUE]If[/COLOR] Range("B16").Value = "" [COLOR=BLUE]And[/COLOR] Range("B17").Value = "" [COLOR=BLUE]Then Exit Sub[/COLOR]

   outName = Sheets("settings").Range("B16") & "_" & Range("B17") [COLOR=GREEN]'ActiveWorkbook.Name[/COLOR]
 [COLOR=GREEN]'**End If[/COLOR]
 CommandButton1.Enabled = [COLOR=BLUE]False[/COLOR]
 [COLOR=BLUE]If[/COLOR] OptionButton1.Value = [COLOR=BLUE]True Then[/COLOR]
  [COLOR=BLUE]With[/COLOR] PDFCreator1
   .cOption("UseAutosave") = 1
   .cOption("UseAutosaveDirectory") = 1
   .cOption("AutosaveDirectory") = ActiveWorkbook.path & "\Temp"
   [COLOR=GREEN]'.cOption("AutosaveDirectory") = ActiveWorkbook.path & "\Sauvegarde"   ICI[/COLOR]

   .cOption("AutosaveFilename") = outName
   .cOption("AutosaveFormat") = 0                            [COLOR=GREEN]' 0 = PDF[/COLOR]
   .cClearCache
  [COLOR=BLUE]End With[/COLOR]
  [COLOR=BLUE]For[/COLOR] i = 1 [COLOR=BLUE]To[/COLOR] Application.Sheets.Count
   Application.Sheets(i).PrintOut Copies:=1, ActivePrinter:="PDFCreator"
  [COLOR=BLUE]Next[/COLOR] i
  [COLOR=BLUE]Do Until[/COLOR] PDFCreator1.cCountOfPrintjobs = Application.Sheets.Count
   DoEvents
   Sleep 1000
  [COLOR=BLUE]Loop[/COLOR]
  Sleep 1000
  PDFCreator1.cCombineAll
  Sleep 1000
  PDFCreator1.cPrinterStop = [COLOR=BLUE]False[/COLOR]
 [COLOR=BLUE]End If[/COLOR]
 [COLOR=BLUE]If[/COLOR] OptionButton2.Value = [COLOR=BLUE]True Then[/COLOR]
  [COLOR=BLUE]With[/COLOR] PDFCreator1
   .cOption("UseAutosave") = 1
   .cOption("UseAutosaveDirectory") = 1
   .cOption("AutosaveDirectory") = ActiveWorkbook.path & "\Temp"
 [COLOR=GREEN]'.cOption("AutosaveDirectory") = ActiveWorkbook.path & "\Sauvegarde"   ICI[/COLOR]


   [COLOR=BLUE]Debug.Print[/COLOR] outName & "-" & ActiveSheet.Name
   .cOption("AutosaveFilename") = outName [COLOR=GREEN]'& "-" & ActiveSheet.Name[/COLOR]
   .cOption("AutosaveFormat") = 0                            [COLOR=GREEN]' 0 = PDF[/COLOR]
   .cClearCache
  [COLOR=BLUE]End With[/COLOR]
  ActiveSheet.PrintOut Copies:=1, ActivePrinter:="PDFCreator"
  [COLOR=BLUE]Do Until[/COLOR] PDFCreator1.cCountOfPrintjobs = 1
   DoEvents
   Sleep 1000
  [COLOR=BLUE]Loop[/COLOR]
  Sleep 1000
  PDFCreator1.cPrinterStop = [COLOR=BLUE]False[/COLOR]
 [COLOR=BLUE]End If[/COLOR]
[COLOR=BLUE]End Sub[/COLOR]

Merci a l'avance
Cordialement
 

YANN-56

XLDnaute Barbatruc
Re : PDF Creator Enregistrer dans deux Dossiers

Bonjour Christian, James, et à ceux qui passeront par ici,

Voici comment j'enregistre une Feuille Excel en PDF:

Code:
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
                              (ByVal hWnd As Long, ByVal lpOperation As String, _
                               ByVal lpFile As String, ByVal lpParameters As String, _
                               ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Sub CONVERSION_EN_PDF()

Dim CREATION_PDF As PDFCreator.clsPDFCreator
Dim Destination As String

Destination = [B][I][COLOR="DarkRed"]ThisWorkbook.Keywords & "\EXERCICE\COMMANDES\" & OUTILS_SAISIE.Label100.Caption & "\FORMAT_PDF\"[/COLOR][/I][/B]

Set CREATION_PDF = New PDFCreator.clsPDFCreator

With CREATION_PDF
'La condition ci-dessous empêche l'ouverture de la boite de dialogue de PDFCreator
If .cStart("/NoProcessingAtStartup") = False Then
MsgBox "Can't initialize PDFCreator.", vbCritical + _
vbOKOnly, "PrtPDFCreator"
Exit Sub
End If
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = Destination
.cOption("AutosaveFilename") = [B][I][COLOR="DarkRed"]NOM_CDE [/COLOR][/I][/B]& ".pdf"
.cOption("AutosaveFormat") = 0 ' 0 = PDF
.cClearCache
End With
'Convertit le document en PDF
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"
'Attend que le document soit entré dans la file de Création
Do Until CREATION_PDF.cCountOfPrintjobs = 1
DoEvents
Loop
CREATION_PDF.cPrinterStop = False
'Attend que la Création du document PDF soit terminée
Do Until CREATION_PDF.cCountOfPrintjobs = 0
DoEvents
Loop
CREATION_PDF.cClose
Set CREATION_PDF = Nothing
End Sub

Je pense qu'en exécutant deux fois " CONVERSION_EN_PDF()"
et en modifiant les variables relatives au chemin, il serait possible
d'arriver à ce que tu cherches.

(En rouge, les éléments à adapter)

Amicalement

Yann
 

James007

XLDnaute Barbatruc
Re : PDF Creator Enregistrer dans deux Dossiers

ReBonjour à tous,

Désolé ... d'avoir lu trop rapidement ta demande ...
Je pense que la solution de Yann est la bonne ...
Entretemps, le code de Ken Puls pour restaurer les paramètres de base de PDF Creator :
Code:
Sub RestoreDefaults()
    Dim objPDF As New PDFCreator.clsPDFCreator

    With objPDF
        If .cStart("/NoProcessingAtStartup") = False Then
            MsgBox "Can't initialize PDFCreator.", vbCritical + _
                    vbOKOnly, "PrtPDFCreator"
            Exit Sub
        End If
        
        'Set Values
        .cOption("UseAutosave") = 0
        .cOption("UseAutosaveDirectory") = 1
        .cOption("AutosaveDirectory") = "\"
        .cOption("AutosaveFilename") = ""
        .cOption("AutosaveFormat") = 0
        .cOption("UseCreationdate") = vbNullString
        .cOption("UseStandardAuthor") = 0
        .cOption("PDFUseSecurity") = 0
        .cOption("PDFUserPass") = 0
        .cOption("PDFUserPassString") = vbNullString
        .cOption("PDFOwnerPass") = 1
        .cOption("PDFOwnerPassString") = vbNullString
        .cOption("PDFEncryptor") = 0
        .cOption("PDFDisallowCopy") = 1
        .cOption("PDFDisallowPrinting") = 0
        .cOption("PDFDisallowModifyContents") = 0
        .cOption("PDFDisallowModifyAnnotations") = 0
        .cOption("PrinterTempPath") = "PDFCreator\"
        
        'Save Values
        .cSaveOptions
    End With
    Set objPDF = Nothing
End Sub

A +
 

YANN-56

XLDnaute Barbatruc
Re : PDF Creator Enregistrer dans deux Dossiers

Bonjour Christian et à ceux qui passeront par ici,

Tu as raison, et je suis un peu comme toi:
Je n'aime pas trop chambouler mon idée de départ. :)

J'ai fais avec mes petits outils en suggérant seulement
de réitérer la procédure; avec entre deux, modifié les variables.

Mais peut-être est-il possible de faire ce que tu cherches
par le biais d'un seul et même code. (Là, je ne sais pas faire... Désolé)

Bonne fin de fin de semaine également à toi.

Amicalement.

Yann
 

kjin

XLDnaute Barbatruc
Re : PDF Creator Enregistrer dans deux Dossiers

Bonjour,
...ça peut pas fonctionner comme tu me dit
Mes deux Dossiers Sauvegarde et Temp
sont dans le même dossier que mon fichier regarde dans mon code
Je ne comprends pas...
Code:
Dim pFld As String
If OptionButton1 Then
pFld = ActiveWorkbook.Path & "\Temp\"
Else
pFld = ActiveWorkbook.Path & "\Sauvegarde\"
End If
'...
.cOption("AutosaveDirectory") = pFld
'...
...pourquoi ça ne fonctionnerait pas ?
A+
kjin
 

YANN-56

XLDnaute Barbatruc
Re : PDF Creator Enregistrer dans deux Dossiers

Re Bonsoir Christian, et à tous,

Je vais devoir apprendre ton code initial, car tu ne veux pas de celui que je t'ai proposé.

Je vais regarder et tenter de t'apporter une solution avec mes petits moyens.

J'entrevois une possibilité, mais comme je suis maladroit avec certaines variables,
je vais devoir préalablement tester.

Je regarde la TV pratiquement jamais, mais ce soir; il y a un film que j'aimerais revoir.

Si plus tard, tu n'as pas de réponses satisfaisantes, je m'y colle... Persuadé d'aboutir.

Amicalement

Yann
 

kjin

XLDnaute Barbatruc
Re : PDF Creator Enregistrer dans deux Dossiers

Re,
je connais le code que tu m'a passé
mais je préfére rester sur le code orignine PDFCreator
1 - Il faudrait nous dire d'où il provient
2 - fournir le code complet (PdfCreator1 ?)
3 - savoir en changer si manifestement, il ne fonctionne pas

Edit :
je viens d'installer PdfCreator - qu'est qu'il ne faut pas faire ! - et testé ceci (origine Ken Puls)...

Code:
'origine : Ken Puls : http://www.excelguru.ca/node/21
Option Explicit

Private Sub CommandButton1_Click()
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim lSheet As Long
Dim lTtlSheets As Long

'/// Change the output file name here! ///
With Sheets("settings")
    sPDFName = .Range("B16") & "_" & .Range("B17") & ".pdf"
End With
If OptionButton1 Then
    sPDFPath = ActiveWorkbook.Path & "\Temp\"
Else
    sPDFPath = ActiveWorkbook.Path & "\Sauvegarde\"
End If
Set pdfjob = New PDFCreator.clsPDFCreator

'Make sure the PDF printer can start
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
    MsgBox "Can't initialize PDFCreator.", vbCritical + _
            vbOKOnly, "Error!"
    Exit Sub
End If

'Set all defaults
With pdfjob
    .cOption("UseAutosave") = 1
    .cOption("UseAutosaveDirectory") = 1
    .cOption("AutosaveDirectory") = sPDFPath
    .cOption("AutosaveFilename") = sPDFName
    .cOption("AutosaveFormat") = 0    ' 0 = PDF
    .cClearCache
End With

'Print the document to PDF
lTtlSheets = Application.Sheets.Count
For lSheet = 1 To Application.Sheets.Count
    On Error Resume Next 'To deal with chart sheets
    If Not IsEmpty(Application.Sheets(lSheet).UsedRange) Then
        Application.Sheets(lSheet).PrintOut copies:=1, ActivePrinter:="PDFCreator"
    Else
        lTtlSheets = lTtlSheets - 1
    End If
    On Error GoTo 0
Next lSheet

'Wait until all print jobs have entered the print queue
Do Until pdfjob.cCountOfPrintjobs = lTtlSheets
    DoEvents
Loop
'Combine all PDFs into a single file and stop the printer
With pdfjob
    .cCombineAll
    .cPrinterStop = False
End With

'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
    DoEvents
Loop
pdfjob.cClose
Set pdfjob = Nothing

End Sub
....et aucun pb !
Je m'en vais désinstaller PDFCreator
A+
kjin
 
Dernière édition:

MuscatMimi

XLDnaute Accro
Re : PDF Creator Enregistrer dans deux Dossiers

Bonsoir Kjin


Merci de l'éffort que tu me consacre

Mais , suis désolé,mais rien ne s'enregistre dans Temp et Sauvegarde

je n'ai pas encore compris et vu ce qui pouvait clocher dans cette procédure


au cliq sur le bouton, pdfJob ne s'initialyze pas

a +++++++++++++++++++++
 

Discussions similaires

Membres actuellement en ligne

Statistiques des forums

Discussions
312 206
Messages
2 086 219
Membres
103 158
dernier inscrit
laufin