Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Word > VBA Word
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 24/01/2012, 18h17   #1
Candidat au titre de Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 60
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 60
Points : 10
Points : 10
Par défaut imprimer dans un fichier

Bonsoir,

Avec l'aide de kiki29 (entre autres),

J'utilise avec plaisir tous les jours le code suivant,
Celui-ci permet d'imprimer des pages en pdf (signets) avec adobe pdf.

J'ai juste un dernier petit problème,

Le code remet bien l'imprimante par défaut à la fin.
Cependant, la case "imprimer dans un fichier" se retrouve cochée.

Est-il possible qu'à la fin du code, l'imprimante et ses options par défaut soit renvoyées.

Merci de votre aide à tous.

Code :
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
Sub WORDTOPDF()
ActivePrinter = "HP Officejet Pro K550 Series"
 
  Selection.GoTo What:=wdGoToBookmark, Name:="c1"
    Selection.Find.ClearFormatting
    Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Copies:=1
 
 
    Selection.GoTo What:=wdGoToBookmark, Name:="c2"
    Selection.Find.ClearFormatting
    Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Copies:=1
 
Dim sNomFichierPS As String
Dim sNomFichierPDF As String
Dim sNomFichierLOG As String
Dim PDFDist As PdfDistiller
Dim PrinterDefault As String, i As Long
Dim sCheminSettings As String, sSetting As String
Dim hwnd As Long
 Selection.WholeStory
    Selection.Range.HighlightColorIndex = wdNoHighlight
    PrinterDefault = Application.ActivePrinter
    Application.ActivePrinter = "Adobe PDF"
    Application.DisplayAlerts = wdAlertsNone
 
    sCheminSettings = "D:\Program Files\Adobe\Acrobat 6.0\Distillr\Settings"
    sSetting = "TOM2012.joboptions"
 
 
        Selection.GoTo What:=wdGoToBookmark, Name:="c3"
        sNomFichierPS = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RECAPITULATIF - " & sNom & ".ps"
        sNomFichierPDF = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RECAPITULATIF - " & sNom & ".pdf"
        sNomFichierLOG = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RECAPITULATIF - " & sNom & ".log"
        ActiveDocument.PrintOut OutputFileName:=sNomFichierPS, _
                                PrintToFile:=True, _
                                Background:=False, _
                                Range:=wdPrintCurrentPage
 
        Set PDFDist = New PdfDistiller
        PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, sCheminSettings & "\" & sSetting
        Set PDFDist = Nothing
        Kill sNomFichierPS
        Kill sNomFichierLOG
 
        ShellExecute hwnd, "Open", sNomFichierPDF, 0&, 0&, SW_SHOWNORMAL
 
        Selection.GoTo What:=wdGoToBookmark, Name:="c4"
        sNomFichierPS = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "COPIE FACTURE - " & sNom & ".ps"
        sNomFichierPDF = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "COPIE FACTURE - " & sNom & ".pdf"
        sNomFichierLOG = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "COPIE FACTURE - " & sNom & ".log"
        ActiveDocument.PrintOut OutputFileName:=sNomFichierPS, _
                                PrintToFile:=True, _
                                Background:=False, _
                                Range:=wdPrintCurrentPage
 
        Set PDFDist = New PdfDistiller
        PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, sCheminSettings & "\" & sSetting
        Set PDFDist = Nothing
        Kill sNomFichierPS
        Kill sNomFichierLOG
 
        ShellExecute hwnd, "Open", sNomFichierPDF, 0&, 0&, SW_SHOWNORMAL
 
        Selection.GoTo What:=wdGoToBookmark, Name:="c5"
        sNomFichierPS = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "FACTURE - " & sNom & ".ps"
        sNomFichierPDF = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "FACTURE - " & sNom & ".pdf"
        sNomFichierLOG = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "FACTURE - " & sNom & ".log"
 
 
        ActiveDocument.PrintOut OutputFileName:=sNomFichierPS, _
                                PrintToFile:=True, _
                                Background:=False, _
                                Range:=wdPrintCurrentPage
 
        Set PDFDist = New PdfDistiller
        PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, sCheminSettings & "\" & sSetting
        Set PDFDist = Nothing
 
        Kill sNomFichierPS
        Kill sNomFichierLOG
 
        ShellExecute hwnd, "Open", sNomFichierPDF, 0&, 0&, SW_SHOWNORMAL
 
        Selection.GoTo What:=wdGoToBookmark, Name:="c6"
        sNomFichierPS = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RAPPORT DDT - " & sNom & ".ps"
        sNomFichierPDF = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RAPPORT DDT - " & sNom & ".pdf"
        sNomFichierLOG = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RAPPORT DDT - " & sNom & ".log"
        ActiveDocument.PrintOut OutputFileName:=sNomFichierPS, _
                                PrintToFile:=True, _
                                Background:=False, _
                                Range:=wdPrintSelection
 
        Set PDFDist = New PdfDistiller
        PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, sCheminSettings & "\" & sSetting
        Set PDFDist = Nothing
 
        Kill sNomFichierPS
        Kill sNomFichierLOG
 
        ShellExecute hwnd, "Open", sNomFichierPDF, 0&, 0&, SW_SHOWNORMAL
 
          Application.ActivePrinter = PrinterDefault
 
 
        Selection.GoTo What:=wdGoToBookmark, Name:="DEBUT"
        Selection.Find.ClearFormatting
End Sub
tom0ne est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 24/01/2012, 19h50   #2
Modérateur
 
Homme Christophe CHAPAT
Spécialiste progiciel
Inscription : février 2010
Messages : 984
Détails du profil
Informations personnelles :
Nom : Homme Christophe CHAPAT
Âge : 25
Localisation : France, Haute Loire (Auvergne)

Informations professionnelles :
Activité : Spécialiste progiciel
Secteur : Service public

Informations forums :
Inscription : février 2010
Messages : 984
Points : 1 597
Points : 1 597
Envoyer un message via MSN à carden752
Bonjour,

Sans lancer une impression, cela me parait délicat car Word conserve la dernière imprimante utilisée jusqu'à sa fermeture.
__________________
Cordialement,
Christophe

Merci de ne pas oublier de mettre résolu quand le sujet l'est. Cela aide tous les DVPnautes dans leur recherche
carden752 est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 24/01/2012, 20h57   #3
Candidat au titre de Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 60
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 60
Points : 10
Points : 10
Merci de ta réponse,

Sur tes conseils, j'ai testé le code suivant (il finit par une impression) :
Code :
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Sub WORDTOPDF()
Dim sNomFichierPS As String
Dim sNomFichierPDF As String
Dim sNomFichierLOG As String
Dim PDFDist As PdfDistiller
Dim PrinterDefault As String, i As Long
Dim sCheminSettings As String, sSetting As String
Dim hwnd As Long
 Selection.WholeStory
    Selection.Range.HighlightColorIndex = wdNoHighlight
    PrinterDefault = Application.ActivePrinter
    Application.ActivePrinter = "Adobe PDF"
    Application.DisplayAlerts = wdAlertsNone
 
    sCheminSettings = "D:\Program Files\Adobe\Acrobat 6.0\Distillr\Settings"
    sSetting = "TOM2012.joboptions"
 
 
        Selection.GoTo What:=wdGoToBookmark, Name:="c3"
        sNomFichierPS = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RECAPITULATIF - " & sNom & ".ps"
        sNomFichierPDF = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RECAPITULATIF - " & sNom & ".pdf"
        sNomFichierLOG = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RECAPITULATIF - " & sNom & ".log"
        ActiveDocument.PrintOut OutputFileName:=sNomFichierPS, _
                                PrintToFile:=True, _
                                Background:=False, _
                                Range:=wdPrintCurrentPage
 
        Set PDFDist = New PdfDistiller
        PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, sCheminSettings & "\" & sSetting
        Set PDFDist = Nothing
        Kill sNomFichierPS
        Kill sNomFichierLOG
 
        ShellExecute hwnd, "Open", sNomFichierPDF, 0&, 0&, SW_SHOWNORMAL
 
        Selection.GoTo What:=wdGoToBookmark, Name:="c4"
        sNomFichierPS = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "COPIE FACTURE - " & sNom & ".ps"
        sNomFichierPDF = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "COPIE FACTURE - " & sNom & ".pdf"
        sNomFichierLOG = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "COPIE FACTURE - " & sNom & ".log"
        ActiveDocument.PrintOut OutputFileName:=sNomFichierPS, _
                                PrintToFile:=True, _
                                Background:=False, _
                                Range:=wdPrintCurrentPage
 
        Set PDFDist = New PdfDistiller
        PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, sCheminSettings & "\" & sSetting
        Set PDFDist = Nothing
        Kill sNomFichierPS
        Kill sNomFichierLOG
 
        ShellExecute hwnd, "Open", sNomFichierPDF, 0&, 0&, SW_SHOWNORMAL
 
        Selection.GoTo What:=wdGoToBookmark, Name:="c5"
        sNomFichierPS = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "FACTURE - " & sNom & ".ps"
        sNomFichierPDF = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "FACTURE - " & sNom & ".pdf"
        sNomFichierLOG = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "FACTURE - " & sNom & ".log"
 
 
        ActiveDocument.PrintOut OutputFileName:=sNomFichierPS, _
                                PrintToFile:=True, _
                                Background:=False, _
                                Range:=wdPrintCurrentPage
 
        Set PDFDist = New PdfDistiller
        PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, sCheminSettings & "\" & sSetting
        Set PDFDist = Nothing
 
        Kill sNomFichierPS
        Kill sNomFichierLOG
 
        ShellExecute hwnd, "Open", sNomFichierPDF, 0&, 0&, SW_SHOWNORMAL
 
        Selection.GoTo What:=wdGoToBookmark, Name:="c6"
        sNomFichierPS = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RAPPORT DDT - " & sNom & ".ps"
        sNomFichierPDF = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RAPPORT DDT - " & sNom & ".pdf"
        sNomFichierLOG = "E:\Documents and Settings\Thom@s\Bureau" & "\" & "RAPPORT DDT - " & sNom & ".log"
        ActiveDocument.PrintOut OutputFileName:=sNomFichierPS, _
                                PrintToFile:=True, _
                                Background:=False, _
                                Range:=wdPrintSelection
 
        Set PDFDist = New PdfDistiller
        PDFDist.FileToPDF sNomFichierPS, sNomFichierPDF, sCheminSettings & "\" & sSetting
        Set PDFDist = Nothing
 
        Kill sNomFichierPS
        Kill sNomFichierLOG
 
        ShellExecute hwnd, "Open", sNomFichierPDF, 0&, 0&, SW_SHOWNORMAL
 
          Application.ActivePrinter = PrinterDefault
 ActivePrinter = "HP Officejet Pro K550 Series"
 
  Selection.GoTo What:=wdGoToBookmark, Name:="c1"
    Selection.Find.ClearFormatting
    Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Copies:=1
 
 
    Selection.GoTo What:=wdGoToBookmark, Name:="c2"
    Selection.Find.ClearFormatting
    Application.PrintOut FileName:="", Range:=wdPrintCurrentPage, Copies:=1
 
 
        Selection.GoTo What:=wdGoToBookmark, Name:="DEBUT"
        Selection.Find.ClearFormatting
End Sub
Malheureusement, la partie du code pour la conversion en pdf vient cocher l'option "imprimer dans un fichier" de l'imprimante "Officejetpro" ,
et donc les dernières impressions ne se font pas.

Merci.
tom0ne est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 25/01/2012, 03h05   #4
Expert Confirmé
 
Homme Philippe
ex Observeur CGG / Analyste prog.
Inscription : juin 2006
Messages : 1 714
Détails du profil
Informations personnelles :
Nom : Homme Philippe
Localisation : France, Finistère (Bretagne)

Informations professionnelles :
Activité : ex Observeur CGG / Analyste prog.

Informations forums :
Inscription : juin 2006
Messages : 1 714
Points : 3 654
Points : 3 654
Salut, à tenter en remplaçant la ligne 101 par
Code :
1
2
Application.PrintOut FileName:="", PrintToFile:=False, Range:=wdPrintCurrentPage, Copies:=1
A utiliser : MZTools et Smart Indenter sur http://excel.developpez.com/outils/?page=vbe
__________________
Pensez à Voter, d'avance merci. ( Pouces en bas à la droite de Citer )
Balisez votre code après l'avoir indenté sous Excel via Smart Indenter
Autre utilitaire : MZ Tools 3.0 VBA

Contribution : Excel / Word / PDF avec Adobe Acrobat Pro / PDFCreator 1 2
kiki29 est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 25/01/2012, 13h38   #5
Candidat au titre de Membre du Club
 
Homme
Inscription : novembre 2011
Messages : 60
Détails du profil
Informations personnelles :
Sexe : Homme

Informations forums :
Inscription : novembre 2011
Messages : 60
Points : 10
Points : 10
Merci kiki,
Tu m'énerves !!!

Évidement ça marche parfaitement !

Merci encore une fois
tom0ne est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 23h52.


 
 
 
 
Partenaires

Hébergement Web