Sub Initialize On Error Goto ErrorHandler Dim s As New NotesSession Dim db As NotesDatabase Dim object As NotesEmbeddedObject Dim dc As NotesDocumentCollection Dim doc As NotesDocument Dim downloadfolder As String Dim extrachar As String Dim filecounter As Integer Dim filecount As Integer Dim filen As Variant Dim antalfiler As Variant Dim i As Integer, x As Integer, y As Integer Dim sFile As String Dim uidoc As NotesUIDocument Dim ws As New NotesUIWorkspace Dim success As Variant ' Create a folder for temporary storage of files downloadfolder = Environ("tmp") Set db = s.CurrentDatabase Set dc = db.UnprocessedDocuments For i = 1 To dc.Count Set doc = dc.GetNthDocument( i ) ' ======= Print document and all its attachments ================= Set uidoc = ws.EditDocument( False , doc , True , ) 'Call uidoc.Print(1) ' ======= Get all attachments and print them ============================= filen=Evaluate("@AttachmentNames",doc) antalfiler=Evaluate("@Attachments", doc) Call uidoc.Close Delete uidoc If antalfiler(0)>0 Then For filecounter=0 To antalfiler(0)-1 x=x+1 Set Object = doc.GetAttachment( filen(filecounter) ) If ( object.Type = EMBED_ATTACHMENT ) Then fileCount = fileCount + 1 If Dir(downloadfolder+"\"+ filen(filecounter))="" Then extrachar="" Else ' Extra character in case there are attachments with the same name extrachar=Left(doc.universalid,4)+"___" End If Call object.ExtractFile (downloadfolder+"\"+extrachar+ filen(filecounter) ) End If Next filecounter End If ' PDF Dim AVDoc As Variant Dim PDDoc As Variant Dim AcroApp As Variant Dim iNumPages As Integer Dim POSTSCRIPT_LEVEL As Integer POSTSCRIPT_LEVEL = 2 ' WORD Dim wordApp As Variant Set wordApp = CreateObject( "Word.Application" ) For y = 0 To filecounter-1 sFile = downloadfolder+"\"+extrachar+ filen(y) Select Case Lcase(Right$(filen(y),3)) Case "doc" ' ====[ Shut down Dialogues in Word ]===== ' VBA constant wdAlertsNone = 0 wordApp.DisplayAlerts = 0 Call wordApp.Documents.open(sFile) Call wordApp.Documents(1).Activate wordApp.Printout Do While wordApp.BackgroundPrintingStatus=1 Print "Skriver ut bilaga "&filen(y) Loop wordApp.ActiveDocument.Close(False) Case "pdf" 'Now print the associated remote PDF file Set AcroApp = CreateObject("AcroExch.AcroApp") Call AcroApp.show Set AVDoc = CreateObject("AcroExch.AVDoc") Call AVDoc.Open( sFile, "" ) Set PDDoc = AVDoc.GetPDDoc iNumPages = PDDoc.GetNumPages Msgbox iNumPages Call AVDoc.PrintPages( 0, iNumPages - 1 , POSTSCRIPT_LEVEL, False, False ) Call AVDoc.Close( True ) End Select ' ---------- Remove file from filesystem ----------------------- Kill sFile Next Next '-------- End Word --------------- wordApp.Quit '-------- End Acrobat --------------- Call AcroApp.Exit Set AcroApp = Nothing Exit Sub ErrorHandler: Call LogError() Exit Sub End Sub