Makro in Excel macht Screenshot und schickt es als Mail, Bilder aber nicht erkannt

  • Excel

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

    Makro in Excel macht Screenshot und schickt es als Mail, Bilder aber nicht erkannt

    Hallo zusammen,

    ich habe folgendes Problem..

    Ich habe ein Makro, welches mir einen Screenshot von einem bestimmten Bereich macht, anschließen eine neue Mail erstellt und diesen einfügt.

    Mein Problem dabei ist, dass in dem Screenshot auch 2 Bilder drinnen sein sollten und diese nicht angezeigt werden können. Habt ihr hier eine Idee? :-/

    Visual Basic-Quellcode

    1. Sub Versand()
    2. 'Versand Makro
    3. 'Dimensionen
    4. Dim oOutlookApp As Object, oOutlookMessage As Object
    5. Dim oFSObj As Object, oFSTextStream As Object
    6. Dim rngeSend As Range, strHTMLBody As String, strTempFilePath As String
    7. Dim ColIndex, RowIndex, Var1, Var2 As Integer
    8. Dim DatumSheet
    9. Sheets("Protokoll").Select
    10. 'Zählt wie viele Zellen kopiert werden sollen
    11. On Error Resume Next
    12. Range("B1:J41").Select
    13. Set rngeSend = Selection
    14. If rngeSend Is Nothing Then Exit Sub 'User pressed Cancel
    15. On Error GoTo 0
    16. 'Pfad für temporäre Datei
    17. Set oFSObj = CreateObject("Scripting.FilesystemObject")
    18. strTempFilePath = oFSObj.GetSpecialFolder(2)
    19. strTempFilePath = strTempFilePath & "\XLRange.htm"
    20. 'Hier wird die HTML-Datei erstellt
    21. ActiveWorkbook.PublishObjects.Add(4, strTempFilePath, _
    22. rngeSend.Parent.Name, rngeSend.Address, 0, "", "").Publish True
    23. 'Outlook session öffnen
    24. Set oOutlookApp = CreateObject("Outlook.Application")
    25. 'Neue email
    26. Set oOutlookMessage = oOutlookApp.CreateItem(0)
    27. For i = 1 To 1 'Für einen Serienbrief muss hier der zweite um die jeweilige Briefanzahl erhöht werden.
    28. 'oOutlookMessage.To = Range("Formeln!A1").Value
    29. oOutlookMessage.To = "EMPFÄNGER DER MAIL"
    30. 'oOutlookMessage.Subject = Range("Formeln!A2").Value & " " & Mid(Time, 1, 2) & ":00 Uhr am " & Date
    31. oOutlookMessage.Subject = "Protokoll vom " & Range("H8")
    32. 'Die HTML-Datei wird geöffnet mit FilesystemObject
    33. Set oFSTextStream = oFSObj.OpenTextFile(strTempFilePath, 1)
    34. 'HTMLBody
    35. strHTMLBody = oFSTextStream.ReadAll
    36. oOutlookMessage.Htmlbody = strHTMLBody
    37. oOutlookMessage.Display
    38. 'oOutlookMessage.send
    39. Cells(1, 1).Select
    40. Next i
    41. ActiveWorkbook.Save
    42. End Sub


    Danke im Voraus und LG
    Benny
    Hallo Benny

    Das liegt daran das die Pfade zu den Bilder in der HTML relativ und nicht absolute hinterlegt sind.
    Siehe hier -> Excel VBA - convert range with pictures and buttons to HTML

    Ich habe dir das einmal in dein Code integriert.
    Gruss HenryV
    Spoiler anzeigen

    Visual Basic-Quellcode

    1. Sub Versand()
    2. 'Versand Makro
    3. 'Dimensionen
    4. Dim oOutlookApp As Object, oOutlookMessage As Object
    5. Dim oFSObj As Object, oFSTextStream As Object
    6. Dim rngeSend As Range, strHTMLBody As String, strTempFilePath As String, strTempFileFullPath As String
    7. Dim ColIndex, RowIndex, Var1, Var2, i As Integer
    8. Dim DatumSheet
    9. Sheets("Protokoll").Select
    10. 'Zählt wie viele Zellen kopiert werden sollen
    11. On Error Resume Next
    12. Set rngeSend = Range("B1:J41")
    13. If rngeSend Is Nothing Then Exit Sub 'User pressed Cancel
    14. On Error GoTo 0
    15. 'Pfad für temporäre Datei
    16. Set oFSObj = CreateObject("Scripting.FilesystemObject")
    17. strTempFilePath = oFSObj.GetSpecialFolder(2) & "\"
    18. strTempFileFullPath = strTempFilePath & "XLRange.htm"
    19. 'Hier wird die HTML-Datei erstellt
    20. Dim imgPrefix As String: imgPrefix = "Myimg"
    21. ActiveWorkbook.PublishObjects.Add(4, strTempFileFullPath, rngeSend.Parent.Name, rngeSend.Address, 0, imgPrefix, "").Publish True
    22. 'Outlook session öffnen
    23. Set oOutlookApp = CreateObject("Outlook.Application")
    24. 'Neue email
    25. Set oOutlookMessage = oOutlookApp.CreateItem(0)
    26. For i = 1 To 1 'Für einen Serienbrief muss hier der zweite um die jeweilige Briefanzahl erhöht werden.
    27. 'oOutlookMessage.To = Range("Formeln!A1").Value
    28. oOutlookMessage.To = "EMPFÄNGER DER MAIL"
    29. 'oOutlookMessage.Subject = Range("Formeln!A2").Value & " " & Mid(Time, 1, 2) & ":00 Uhr am " & Date
    30. oOutlookMessage.Subject = "Protokoll vom " & Range("H8")
    31. 'Die HTML-Datei wird geöffnet mit FilesystemObject
    32. Set oFSTextStream = oFSObj.OpenTextFile(strTempFileFullPath, 1)
    33. 'HTMLBody
    34. strHTMLBody = oFSTextStream.ReadAll
    35. Dim j As Integer
    36. Dim strData() As String
    37. strData() = Split(strHTMLBody, vbCrLf)
    38. '~~> Loop through the file
    39. For j = LBound(strData) To UBound(strData)
    40. '~~> Here we will first get the image names
    41. If InStr(1, strData(j), "Myimg_", vbTextCompare) And InStr(1, strData(j), ".png", vbTextCompare) Then
    42. '~~> Insert actual path to the images
    43. Debug.Print strData(j)
    44. strData(j) = Replace(strData(j), "XLRange-Dateien/", strTempFilePath & "XLRange-Dateien/")
    45. Debug.Print strData(j)
    46. End If
    47. Next j
    48. '~~> Rejoin to get the new html string
    49. strHTMLBody = Join(strData, vbCrLf)
    50. oOutlookMessage.HTMLBody = strHTMLBody
    51. oOutlookMessage.Display
    52. 'oOutlookMessage.send
    53. Cells(1, 1).Select
    54. Next i
    55. ActiveWorkbook.Save
    56. End Sub