Bonjour et merci à tous sa fonctionne je passe pas par la recherche du processus car il faut testé sur seven si celà est compatible windows 2000.
Bref je fais sa et je n'extrait plus les documents car les documents sont dans un répertoires dans le réseau:
J'avoue c'est un code bourrin, je compte le mettre dans un agent et appeler cette agent avec @toolmacro.
Au début c'était extraire les documents, en faites c facilité la vie des utilisateurs qui ne veulent pas ouvrir chaque pdf mais imprimés une liste.
Ben merci avance, il manque les fonctions que met par la suite :
- Code : Tout sélectionner
'A mettre dans déclaration :
'/////////////////////////////////////////////////////////////////////////////////////
' Afin utiliser la fonction impression pour acrobat reader sans passer par le chemin
'/////////////////////////////////////////////////////////////////////////////////////
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (Byval hwnd As Long, Byval lpszOp As String, Byval lpszFile As String, Byval lpszParams As String, _
Byval LpszDir As String, Byval FsShowCmd As Long) As Long
' a mettre dans un bouton d'une vue
- Code : Tout sélectionner
Sub Click(Source As Button)
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
' Etape 0 : Gérer le temps éxécution pour supprimer le processus
'//////////////////////////////////////////////////////////////////////////
Dim current_deb As String
Dim current_fin As String
Dim debut As Integer
Dim fin As Integer
Dim result As Integer
'le départ
current_deb = Time$()
'/////////////////////////////////////////////////////////////////////////////////////
' Etape 1 : Utilisation de fonction avec requête Query
'/////////////////////////////////////////////////////////////////////////////////////
'-------------------------------------------------------------------------------------
'Liste toute les imprimantes par défaut
'Affiche boite de dialogue afin de séléctionner la bonne imprimante
'-------------------------------------------------------------------------------------
Dim nomimp As String
nomimp = PrinterList()
'si la personne n'a pas séléctionner d'imprimante je quitte
If nomimp ="" Then
Msgbox "Vous n'avez pas séléctionner imprimante.",16,"Erreur"
Exit Sub
End If
'-------------------------------------------------------------------------------------
'Change imprimante par défaut
'-------------------------------------------------------------------------------------
Dim change As String
change = PrinterDefautSet( nomimp)
'/////////////////////////////////////////////////////////////////////////////////////
' Etape 2 : On gère les fichiers séléctionnées de la vues
'/////////////////////////////////////////////////////////////////////////////////////
' Variable pour récupérer le nom du fichier dans la vue
'-------------------------------------------------------------------------------------
Dim Session As New NotesSession
Dim Vue As NotesView
Dim Col As NotesDocumentCollection
Dim db As NotesDatabase
Dim Doc As NotesDocument
'-------------------------------------------------------------------------------------
'Pour la gestion impression du fichier pdf
Dim pathfile As String
Dim fname As String
Dim ret As Byte
Dim var As Boolean
Dim liste List As String
fname=""
'-------------------------------------------------------------------------------------
' Variable pour retrouver le fichier
Dim rItem As Variant
Dim sFichier, tFichier, sJour, sMois, sAnnee, sDate As String
Dim iReponse, iPosition, siPosition As Integer
Dim chemin As String
'le chemin des fichiers validés
' adresse ip du serveur suivie du chemin
chemin = "XXXXX\XXX.pdf"
' Travail sur la base actuel
Set db = Session.CurrentDatabase
' Travail sur la vue
Set Vue = db.GetView("xxxxx") 'le nom de la vue à la place de xxx
' Met les documents sélectionnés dans un collection (tableau)
Set Col = db.UnprocessedDocuments
' Regarde si il y a aucun document séléctionnés
If Col.Count = 0 Then
Exit Sub
End If
' Regarde si au moins un document est sélectionné
If Col.Count > 0 Then
' Se positionne sur le premier document de la collection
Set Doc = Col.GetFirstDocument
' Boucle tant que des documents sont dans la collection
Do While Not (Doc Is Nothing)
' Récupère le champs avec les pièces jointes
Set rItem = Doc.GetFirstItem("plan")
' Test le type de champs pour savoir si c'est bien champs texte riche
If (rItem.Type = RICHTEXT) Then
' Boucle pour toutes les pièces jointes du champs
Forall o In rItem.EmbeddedObjects
' Test si l'object trouvé est bien une pièce jointe
If (o.Type = EMBED_ATTACHMENT) Then
' Test si le fichier existe déjà
sFichier = Dir$(chemin & o.Source, 0)
If sFichier <> "" Then
'////////////////////////////////////////////////////////////////////////////
'ETAPE 3 : IMPRESSIONS DU FICHIER PDF
'///////////////////////////////////////////////////////////////////////////
' Le fichier existe on peut le récupérer pour impression
fname = Trim(chemin & o.Source) 'le chemin du fichier
pathFile=Strleftback(fname,"\")
ret = ShellExecute(1, "Print", fname, "", pathFile, 0) 'éxécute impression
'//////////////////////////////////////////////////////////////////////////////
' Pause
'--------------------------------------------------------
Sleep 1 '1 seconde
'-------------------------------------------------------
'Msgbox Cstr(o.Source) 'verification des fichiers
End If
End If
' la boucle continu tant que des pièces jointes sont dans l'objet
End Forall
End If
' la boucle continu tant que des documents sont dans la collection
Set Doc = Col.GetNextDocument(Doc)
Loop
'-----------------------------------------------------
' Pause selon le temps éxécution
'--------------------------------------------------------
current_fin = Time$()
'Minute départ
debut = Minute(current_deb)
'Minute arrivé
fin = Minute(current_fin)
result = fin - debut
If result <> 0 Then
Msgbox "minute " & result
Sleep result
Else
'Seconde départ
debut = Second(current_deb)
'Seconde arrivé
fin = Second(current_fin)
result = fin - debut
Msgbox "seconde " & result
Sleep result
End If
'///////////////////////////////////////////////////////////////////////////////////////
' ETAPE 4 : Suppression du processus AcrobatReader
'////////////////////////////////////////////////////////////////////////////////////
'Mettre une temporisation
Dim rt As Integer
rt = Shell("taskkill /F /IM AcroRd32.exe", 6)
'-----------------------------------------------------------------------------------
Set Col = Nothing
Set Vue = Nothing
Set db = Nothing
End If
'///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
End Sub
Fonctions de mickael (fonctionne trés bien pas testé sur seven ):
- Code : Tout sélectionner
'/////////////////////////////////////////////////////////////////////////////////////
'change l'imprimante par défaut
'/////////////////////////////////////////////////////////////////////////////////////
Function PrinterDefautSet(wPrinter As String)
Dim objWMIService As Variant
Dim vrPrinter As Variant
Const Computer = "."
On Error Goto ErreurHandle
If Trim(wPrinter) = "" Then
Error 9999,"wPrinter is empty"
Exit Function
End If
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" +Computer + "\root\cimv2")
Set vrPrinter = objWMIService.ExecQuery ({Select * from Win32_Printer Where Name = '}+Trim(Replace(wPrinter,"\","\\"))+{'})
Forall objPrinter In vrPrinter
If Ucase(Trim(objPrinter.Name))=Ucase(Trim(wPrinter)) Then
Call objPrinter.SetDefaultPrinter()
PrinterDefautSet = Trim(objPrinter.Name)
Exit Forall
End If
End Forall
If Trim(PrinterDefautSet) = "" Then
'si jamais on ne trouve pas l'imprimante on passe toute les imprimante en revue
Set vrPrinter = Nothing
Set vrPrinter = objWMIService.ExecQuery ("Select * from Win32_Printer")
Forall objPrinter In vrPrinter
If Ucase(Trim(objPrinter.Name))=Ucase(Trim(wPrinter)) Then
Call objPrinter.SetDefaultPrinter()
'PrinterDefautSet = Trim(objPrinter.Name)
Exit Forall
End If
End Forall
End If
Set vrPrinter = Nothing
Set objWMIService = Nothing
Exit Function
ErreurHandle:
Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
Exit Function
End Function
'/////////////////////////////////////////////////////////////////////////////////////
'Liste toutes les imprimantes installé"
'je l'ai améliorer en ajoutant une autre fonction qui a pour but afficher
'dans une liste toutes les imprimantes disponibles
'////////////////////////////////////////////////////////////////////////
Function PrinterList() As String
' http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+Tutorials+Printing.txt
Dim lstPrinter List As String
Dim vrPrinter As Variant
Dim i As Integer
Dim objWMIService As Variant
Const Computer = "."
On Error Goto ErreurHandle
lstPrinter(0)=""
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" +Computer + "\root\cimv2")
Set vrPrinter = objWMIService.ExecQuery ("Select * from Win32_Printer")
i=0
Forall objPrinter In vrPrinter
lstPrinter(i)=Cstr(objPrinter.Name)
'PrinterList = PrinterList + lstPrinter(i) +Chr(10)
i=i+1
End Forall
Set vrPrinter = Nothing
Set objWMIService = Nothing
'PrinterList = lstPrinter
'on appel un fonction dans laquelle on affiche le nom des imprimantes
PrinterList = listChoix (lstPrinter, i)
Erase lstPrinter
Exit Function
ErreurHandle:
Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
Erase lstPrinter
lstPrinter(0)=""
'PrinterList = lstPrinter
Erase lstPrinter
Exit Function
End Function
'/////////////////////////////////////////////////////////////////////////////////////
' Fonctions qui affiche dans un prompt toutes les imprimantes sauf
' "CutePDF Writer" et "Microsoft XPS Document Writer"
'////////////////////////////////////////////////////////////////////////
Function listChoix(nom List As String , i As Integer) As String
On Error Goto ErreurHandle
Dim workspace As New NotesUIWorkspace
Dim response As Variant
Dim j,k As Integer
If i= 0 Then
Exit Function
End If
Dim tableau ( 1 To 6) As String
j = 1
Forall v In nom
If v <> "Microsoft XPS Document Writer" Then
If v <>"CutePDF Writer" Then
'on veut seulement récupérer les imprimantes et non cute pdf ou autre chose
tableau (j) = v
j = j +1
End If
End If
End Forall
response = workspace.Prompt (PROMPT_OKCANCELLIST, _
"Imprimante", _
"Selectionner votre Imprimante", , tableau)
'response récupère le nom de l'imprimante
listChoix = Cstr(response)
Exit Function
ErreurHandle :
Msgbox "Erreur function Listchoix"
Exit Function
End Function