Outlook: VBA - Anhang lässt sich nicht in Filesystem schreiben

  • Sonstige

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von rockotron.

    Outlook: VBA - Anhang lässt sich nicht in Filesystem schreiben

    Hallo,

    ich habe folgendes Problem. Ich erzeuge per VBA eine Kopie der originalen zu versendenden Mail, welche nun natürlich auch die Anhänge des Originals erhalten soll. Diese müssen, soweit ich weiß, zwischengespeichert werden, bevor sie in das neue Mail-Objekt übernommen werden können. Unter Windows 7 (Outlook 2003) habe ich nun das Problem, dass ich grundsätzlich keine Schreibberechtigungen auf den neu erzeugten Ordner erhalte (Homepath\Mail)(siehe Zeile 32). Hat jemand eine Idee, wie ich das umgehen kann?

    Mein Code:

    Visual Basic-Quellcode

    1. Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
    2. Dim strTmpDir As String
    3. Dim strResult As String
    4. Dim x, nCheck, nImp, nAtt, nIndex As Integer
    5. Dim oMail As Outlook.MailItem
    6. Dim oInsp As Outlook.Inspector
    7. Dim oRecip As Outlook.Recipient
    8. Dim oAtt As Outlook.Attachment
    9. Set oMail = Outlook.Application.CreateItem(olMailItem)
    10. Set oInsp = oMail.GetInspector
    11. nAtt = item.Attachments.Count
    12. nIndex = 1
    13. With oMail
    14. .Subject = item.Subject
    15. .Body = item.Body
    16. If nAtt > 0 Then
    17. Do
    18. strTmpDir = Environ(nIndex)
    19. nIndex = nIndex + 1
    20. Loop Until Left(strTmpDir, 8) = "HOMEPATH"
    21. strTmpDir = "C:" + Replace(strTmpDir, "HOMEPATH=", "") + "\Mail"
    22. If Dir(strTmpDir, vbDirectory) = "" Then
    23. MkDir (strTmpDir)
    24. End If
    25. For Each oAtt In item.Attachments
    26. oAtt.SaveAsFile (strTmpDir)
    27. Next
    28. End If
    29. End With
    30. x = item.Recipients.Count
    31. nImp = item.Importance
    32. If x > 0 Then
    33. With oMail
    34. 'Setzen der Dringlichkeit für zweite Mail
    35. If nImp = 0 Then
    36. .Importance = olImportanceLow
    37. ElseIf nImp = 1 Then
    38. .Importance = olImportanceNormal
    39. ElseIf nImp = 2 Then
    40. .Importance = olImportanceHigh
    41. End If
    42. For x = item.Recipients.Count To 1 Step -1
    43. If InStr(item.Recipients(x).Address, "@") > 0 Then
    44. nCheck = item.Recipients(x).Type
    45. Set oRecip = .Recipients.Add(item.Recipients(x).Address)
    46. 'Prüfung, ob Status des Empfängers To, CC oder BCC ist
    47. If nCheck = 1 Then
    48. oRecip.Type = olTo
    49. ElseIf nCheck = 2 Then
    50. oRecip.Type = olCC
    51. ElseIf nCheck = 3 Then
    52. oRecip.Type = olBCC
    53. End If
    54. item.Recipients.Remove (x)
    55. End If
    56. Next
    57. End With
    58. If oMail.Recipients.Count > 0 Then
    59. Call SendNonExchange(oMail, oInsp)
    60. Else
    61. Set oMail = Nothing
    62. Set oInsp = Nothing
    63. End If
    64. ........