Bilder Mail Attachments drucken

  • Outlook

Es gibt 23 Antworten in diesem Thema. Der letzte Beitrag () ist von Sam85.

    Was steht in "attachment_directory"? Mal ins Blaue: strFile = attachment_directory & "\" & otlAtt.FileName

    Edit:
    Nimm mal "On Error Resume Next" raus. Und am Anfang des Moduls die Anweisung Option Explicit setzen. Dann wirst Du sehen wo die Probleme liegen könnten. "attachment_directory" ist nicht deklariert, und somit leer.

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „mumpel“ ()

    Ja ich habe mich vorhin auch schon gefragt, was Attachment_Directory ist und wie es deklariert werden soll. Hier ist der Link wo ich es gefunden habe.
    Oder stellt Attachment_Directory einfach nur den Default Pfad da? Bzw. kann ich einfach einen Pfad hinterlegen?
    Weshalb nutzt Du nicht "strFilePath" (hast Du ja am Anfang des Codes angegeben) anstelle von "Attachment_Directory"? Oder Du gibst den Pfad direkt an.

    "Attachment_Directory" ist vermutlich ein Überbleibsel aus einer alten Outlookversion.
    Das mit FilePath habe ich versucht, da kommt aber nichts raus...deshalb hat mich das auch stutzig gemacht.
    Hab es jetzt mal ganz weggelassen...im festgelegten Verzeichnis stehen sie jetzt drin und drucken geht auch.
    Mal schauen was bei einen anderen Benutzer passiert.

    EDIT:
    Muss jetzt nur den Timer etwas höher setzen, damit die Dateien nicht zu schnell zerstört werden.
    Spoiler anzeigen


    Visual Basic-Quellcode

    1. Option Explicit
    2. #If VBA7 Then
    3. Private Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    4. ByVal hwnd As LongPtr, _
    5. ByVal lpOperation As String, _
    6. ByVal lpFile As String, _
    7. ByVal lpParameters As String, _
    8. ByVal lpDirectory As String, _
    9. ByVal nShowCmd As LongPtr) As LongPtr
    10. Public Declare PtrSafe Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As LongPtr)
    11. #Else
    12. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    13. ByVal hwnd As Long, _
    14. ByVal lpOperation As String, _
    15. ByVal lpFile As String, _
    16. ByVal lpParameters As String, _
    17. ByVal lpDirectory As String, _
    18. ByVal nShowCmd As Long) As Long
    19. Public Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    20. #End If
    21. Const strFilePath As String = "C:\Anlagen"



    Visual Basic-Quellcode

    1. Public Sub PrintSelectedAttachments()
    2. Dim otlExplorer As Outlook.Explorer
    3. Dim otlSelection As Outlook.Selection
    4. Dim obj As Object
    5. Set otlExplorer = Application.ActiveExplorer
    6. Set otlSelection = otlExplorer.Selection
    7. For Each obj In otlSelection
    8. If TypeOf obj Is Outlook.MailItem Then PrintAttachments obj
    9. Next
    10. Set otlSelection = Nothing
    11. Set otlExplorer = Nothing
    12. Sleep 5000
    13. Shell "TaskKill /im acrobat.exe /f"
    14. Shell "TaskKill /im acrord32.exe /f"
    15. Kill (strFilePath & "\*.*")
    16. End Sub



    Visual Basic-Quellcode

    1. Private Sub PrintAttachments(ByVal otlMail As Outlook.MailItem)
    2. Dim otlAttCounter As Outlook.Attachments
    3. Dim otlAtt As Outlook.Attachment
    4. Dim strFile As String
    5. Dim strFileType As String
    6. On Error Resume Next
    7. If Dir(strFilePath, vbDirectory) = "" Then MkDir (strFilePath)
    8. Set otlAttCounter = otlMail.Attachments
    9. If otlAttCounter.Count Then
    10. For Each otlAtt In otlAttCounter
    11. strFileType = LCase$(Right$(otlAtt.FileName, 4))
    12. Select Case strFileType
    13. Case ".xls", ".xlsx", ".doc", ".docx", ".pdf"
    14. strFile = otlAtt.FileName
    15. otlAtt.SaveAsFile (strFile)
    16. ShellExecute 0, "print", strFile, vbNullString, vbNullString, 0
    17. Case ".tif", ".jpg", ".jpeg", ".png"
    18. strFile = otlAtt.FileName
    19. otlAtt.SaveAsFile (strFile)
    20. Shell "C:\Program Files\IrfanView\i_view64.exe " & """" & strFilePath & "\" & strFile & """" & " /print=" & GetDefaultPrinterByName()
    21. End Select
    22. Next otlAtt
    23. End If
    24. Set otlAttCounter = Nothing
    25. End Sub



    Visual Basic-Quellcode

    1. Option Explicit
    2. #If VBA7 Then
    3. Private Declare PtrSafe Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" ( _
    4. ByVal lpAppName As String, _
    5. ByVal lpKeyName As String, _
    6. ByVal lpDefault As String, _
    7. ByVal lpReturnedString As String, _
    8. ByVal nSize As Long) As Long
    9. #Else
    10. Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" ( _
    11. ByVal lpAppName As String, _
    12. ByVal lpKeyName As String, _
    13. ByVal lpDefault As String, _
    14. ByVal lpReturnedString As String, _
    15. ByVal nSize As Long) As Long
    16. #End If
    17. Public Function GetDefaultPrinterByName() As String
    18. Dim strBuffer As String
    19. Dim lngBuffer As Long
    20. Dim lngReturn As Long
    21. strBuffer = Space(8192)
    22. lngReturn = GetProfileString("windows", "device", "", strBuffer, Len(strBuffer))
    23. If lngReturn Then
    24. strBuffer = Mid$(strBuffer, 1, lngReturn)
    25. lngBuffer = InStr(strBuffer, ",")
    26. GetDefaultPrinterByName = Mid$(strBuffer, 1, lngBuffer - 1)
    27. Else
    28. GetDefaultPrinterByName = ""
    29. End If
    30. End Function


    Dieser Beitrag wurde bereits 4 mal editiert, zuletzt von „Sam85“ ()