Fermer fichier PDF

guitarde

XLDnaute Junior
Bonjour,

J'ai une macro qui me permet de créer un fichier pdf, celui-ci s'affiche toujours à l'écran et est sauvegardé avec le nom que j'ai déterminé. Je cherche une facon de fermer automatiquement ce fichier.

Dans mon excemple le fichier PDF s'appelle : Printout.pdf

J'ai essayé Close 'Printout.pdf' sans succès.


Merci pour votre aide...
Eric
 

guitarde

XLDnaute Junior
J'ai finalement trouvé ma solution via la base de registre

'Pour ne pas avoir de Preview du PDF, sinon mettre = 1
WriteRegistry HKEY_CURRENT_USER, _
'Software\\Adobe\\Acrobat PDFWriter\\', _
'bExecViewer', _
'0'


Voici le code au complet pour le bénéfice des autres

===========================

Option Explicit

Private Const HKEY_CURRENT_USER = &H80000001
Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_NOTIFY = &H10
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000
Private Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or _
KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or _
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or _
KEY_CREATE_LINK) And (Not SYNCHRONIZE))

Private Declare Function RegOpenKeyEx Lib 'ADVAPI32.DLL' Alias 'RegOpenKeyExA' _
(ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, _
phkResult As Long) As Long

Private Declare Function RegCloseKey Lib 'ADVAPI32.DLL' (ByVal hKey As Long) As Long

Private Declare Function RegSetValueExA Lib 'ADVAPI32.DLL' _
(ByVal hKey As Long, ByVal sValueName As String, _
ByVal dwReserved As Long, ByVal dwType As Long, _
ByVal sValue As String, ByVal dwSize As Long) As Long

Private Declare Function RegCreateKeyA Lib 'ADVAPI32.DLL' _
(ByVal hKey As Long, ByVal sSubKey As String, ByRef hkeyResult As Long) As Long

Private Function WriteRegistry(TheKey As Long, _
Folder As String, _
Key As String, _
Value As Variant) As Boolean
Dim hKey As Long, x As Long

RegOpenKeyEx TheKey, Folder, 0, KEY_ALL_ACCESS, hKey
If hKey <> 0 Then
x = RegSetValueExA(hKey, Key, 0, 1, Value, Len(Value) + 1)
WriteRegistry = (x = 0)
RegCloseKey hKey
End If
End Function

Sub PrintPdfToC()
Dim vActivePrinter

'identifie l'imprimante active
vActivePrinter = Application.ActivePrinter


'Génère le fichier pdf sur c:\\printout.pdf
WriteRegistry HKEY_CURRENT_USER, _
'Software\\Adobe\\Acrobat PDFWriter\\', _
'PDFFileName', _
'C:\\Printout.pdf'

'Pour ne pas avoir de Preview du PDF, sinon mettre = 1
WriteRegistry HKEY_CURRENT_USER, _
'Software\\Adobe\\Acrobat PDFWriter\\', _
'bExecViewer', _
'0'

Application.ActivePrinter = 'Acrobat PDFWriter on LPT1:'
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
'Acrobat PDFWriter on LPT1:'


'Remet l'imprimante active du début
Application.ActivePrinter = vActivePrinter

End Sub
 

Discussions similaires

Réponses
11
Affichages
241

Statistiques des forums

Discussions
312 196
Messages
2 086 088
Membres
103 116
dernier inscrit
kutobi87