Thema Datum  Von Nutzer Rating
Antwort
20.06.2024 09:45:50 Tonja
NotSolved
20.06.2024 12:22:45 Gast25402
NotSolved
21.06.2024 07:32:48 Tonja
NotSolved
21.06.2024 12:19:34 Gast87331
NotSolved
21.06.2024 13:42:09 Gast40664
NotSolved
20.06.2024 19:05:46 ralf_b
NotSolved
21.06.2024 07:38:57 Tonja
NotSolved
21.06.2024 13:32:29 ralf_b
NotSolved
Rot Exceldaten in geöffnetes Mail kopieren
22.06.2024 11:45:50 Gast10753
NotSolved
24.06.2024 14:49:23 Tonja
NotSolved
25.06.2024 10:31:02 Gast33625
NotSolved
27.06.2024 12:30:04 Gast60368
NotSolved
27.06.2024 14:04:48 Gast93251
NotSolved

Ansicht des Beitrags:
Von:
Gast10753
Datum:
22.06.2024 11:45:50
Views:
76
Rating: Antwort:
  Ja
Thema:
Exceldaten in geöffnetes Mail kopieren

Versuch mal das hier:

Ungetestet. Ob das deiner Vorstellung entspricht, weiss ich nicht.

Sub SendEmailWithExcelData()
    Dim OutlookApp As Object
    Dim OutlookMail As Object
    Dim ws As Worksheet
    Dim EmailBody As String
    Dim FilteredRow As Range
    Dim i As Integer, j As Integer
    Dim olInspector As Object

    ' Set the active sheet
    Set ws = ActiveSheet
    
    ' Find the filtered row
    On Error Resume Next
    Set FilteredRow = ws.Range("A3:A" & ws.Cells(ws.Rows.Count, "A").End(xlUp).Row).SpecialCells(xlCellTypeVisible).EntireRow
    On Error GoTo 0
    
    ' Check if only one row is visible
    If Not FilteredRow Is Nothing Then
        If FilteredRow.Count = 1 Then
            ' Build the email body with an HTML table
            EmailBody = "<html><body><table border='1'>"
            
            ' Add headers to the table
            EmailBody = EmailBody & "<tr><th>ws.Cells(2, 2).Value</th>"
            For i = 9 To 15 ' I2:O2 corresponds to columns 9 to 15
                EmailBody = EmailBody & "<th>" & ws.Cells(2, i).Value & "</th>"
            Next i
            For i = 35 To 51 ' AI2:AY2 corresponds to columns 35 to 51
                EmailBody = EmailBody & "<th>" & ws.Cells(2, i).Value & "</th>"
            Next i
            EmailBody = EmailBody & "</tr>"
            
            ' Add data to the table
            EmailBody = EmailBody & "<tr><td>" & ws.Range("B2").Value & "</td>"
            For i = 9 To 15
                EmailBody = EmailBody & "<td>" & ws.Cells(FilteredRow.Row, i).Value & "</td>"
            Next i
            For i = 35 To 51
                EmailBody = EmailBody & "<td>" & ws.Cells(FilteredRow.Row, i).Value & "</td>"
            Next i
            EmailBody = EmailBody & "</tr>"
            
            ' Close the table and HTML tags
            EmailBody = EmailBody & "</table></body></html>"
            
            ' Create a new Outlook application object
            Set OutlookApp = CreateObject("Outlook.Application")
            
            ' Find the open email
            If OutlookApp.Inspectors.Count > 0 Then
                For Each olInspector In OutlookApp.Inspectors
                    If olInspector.CurrentItem.Class = olMail Then
                        Set OutlookMail = olInspector.CurrentItem

                        ' Update the email body
                        OutlookMail.HTMLBody = OutlookMail.HTMLBody & "<br><br>" & EmailBody
                        OutlookMail.Display ' Stellen Sie sicher, dass die E-Mail geöffnet bleibt
                    End If
                Next olInspector
            Else
                MsgBox "Es wurde keine geöffnete Mail gefunden.", vbInformation
            End If

        Else
            MsgBox "Es sind keine oder mehrere Zeilen gefiltert.", vbExclamation
        End If
    Else
        MsgBox "Keine gefilterte Zeile.", vbExclamation
    End If

    ' Clean up
    Set FilteredRow = Nothing
    Set ws = Nothing
    Set OutlookMail = Nothing
    Set OutlookApp = Nothing
End Sub

 


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
20.06.2024 09:45:50 Tonja
NotSolved
20.06.2024 12:22:45 Gast25402
NotSolved
21.06.2024 07:32:48 Tonja
NotSolved
21.06.2024 12:19:34 Gast87331
NotSolved
21.06.2024 13:42:09 Gast40664
NotSolved
20.06.2024 19:05:46 ralf_b
NotSolved
21.06.2024 07:38:57 Tonja
NotSolved
21.06.2024 13:32:29 ralf_b
NotSolved
Rot Exceldaten in geöffnetes Mail kopieren
22.06.2024 11:45:50 Gast10753
NotSolved
24.06.2024 14:49:23 Tonja
NotSolved
25.06.2024 10:31:02 Gast33625
NotSolved
27.06.2024 12:30:04 Gast60368
NotSolved
27.06.2024 14:04:48 Gast93251
NotSolved