Clever-Excel-Forum

Normale Version: via CommandButton Mail versenden
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hi liebes Forum,

ich möchte via CommandButton den dynamsichen Teil einer EXCEL-Tabelle per Mail versenden.
Folgenden Code habe ich mir zurecht geschustert, aber es möchte nicht richtig funktionieren.
Es wird eine neue HTML-Mail mit Empfänger und Empfänger in Kopie eröffnet, aber im body steht einfach nur eine "0".
Könnt ihr mir leicht verdaulich mitteilen, was ich hier falsch mache.

Ich nutze die APPs des Office365.

VG dev5fr

Code:
Private Sub CommandButton1_Click()
On Error Resume Next
Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")
With olApp.CreateItem(0)
strhtml = Range("A7").Value & strhtml = Range("B7").Value & strhtml = Range("C7").Value & strhtml = Range("D7").Value & " <br>"
strhtml = Range("A8").Value & strhtml = Range("B8").Value & strhtml = Range("C8").Value & strhtml = Range("D8").Value & " <br>"
strhtml = Range("A9").Value & strhtml = Range("B9").Value & strhtml = Range("C9").Value & strhtml = Range("D9").Value & " <br>"
strhtml = Range("A10").Value & strhtml = Range("B10").Value & strhtml = Range("C10").Value & strhtml = Range("D10").Value & " <br>"
strhtml = Range("A11").Value & strhtml = Range("B11").Value & strhtml = Range("C11").Value & strhtml = Range("D11").Value & " <br>"
strhtml = Range("A12").Value & strhtml = Range("B12").Value & strhtml = Range("C12").Value & strhtml = Range("D12").Value & " <br>"
.to = "mail@an.de"
.cc = "kopie@an.de"
.htmlbody = strhtml
.display
End With
Set olApp = Nothing
End Sub
Hallo,

was bezweckst Du mit dieser Codezeile?

Code:
strhtml = Range("A7").Value & strhtml = Range("B7").Value & strhtml = Range("C7").Value & strhtml = Range("D7").Value & " <br>"
Da kann auch nur 0 ausgegeben werden wenn der Vergleich 0 ergibt. Schau Dir bitte mal an was Du da in den Code geschrieben hast, und denke dann darüber nach.
Es soll der Inhalt mehrer Zellen hintereinander weggeschrieben werden.
In der Spalte A ist die ID, Spalte B Vorname, Spalte C Nachname, Spalte D ein dynamischer Wert.
Einen "Vergleich" wollte ich gar nicht umsetzen Angel

Das Ergebnis soll in etwa so aussehen:

4711 Hans Will 78
0815 Ulli Meier 56
...
Ich wollte die Zellen mit dem &  "verketten".
Aber die Syntax scheint nicht korrekt zu sein.
Wenn ich den Code nur auf eine Zelle reduziere, dann funktioniert ist.

Code:
Private Sub CommandButton1_Click()
On Error Resume Next
Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")
With olApp.CreateItem(0)
strhtml = Range("A7").Value & " <br>"
.to = "mail@an.de"
.cc = "kopie@an.de"
.htmlbody = strhtml
.display
End With
Set olApp = Nothing
End Sub
strhtml = Range("A7").Value
strhtml = strhtml & Range("B7").Value
strhtml = strhtml & Range("C7").Value
strhtml = strhtml & Range("D7").Value & " <br>"
strhtml = strhtml & Range("A8").Value
strhtml = strhtml & Range("B8").Value
strhtml = strhtml & Range("C8").Value
strhtml = strhtml & Range("D8").Value & " <br>"
strhtml = strhtml & Range("A9").Value
strhtml = strhtml & Range("B9").Value
strhtml = strhtml & Range("C9").Value
strhtml = strhtml & Range("D9").Value & " <br>"
strhtml = strhtml & Range("A10").Value
strhtml = strhtml & Range("B10").Value
strhtml = strhtml & Range("C10").Value
strhtml = strhtml & Range("D10").Value & " <br>"
strhtml = strhtml & Range("A11").Value
strhtml = strhtml & Range("B11").Value
strhtml = strhtml & Range("C11").Value
strhtml = strhtml & Range("D11").Value & " <br>"
strhtml = strhtml & Range("A12").Value
strhtml = strhtml & Range("B12").Value
strhtml = strhtml & Range("C12").Value
strhtml = strhtml & Range("D12").Value & " <br>"


VBA/HTML-CodeConverter, AddIn für Excel 2002-2019 (32-bit) und Excel 365 (32-bit Desktop-Version)
In VBA geschrieben von Lukas Mosimann. Projektbetreuung: René Holtz


Code erstellt und getestet in Excel 365 32-bit Desktopversion
Codedarstellung mit VBAHTML 12.6.0 erstellt.


(10.05.2021, 19:26)dev5fr schrieb: [ -> ]Einen "Vergleich" wollte ich gar nicht umsetzen Angel
So wie Du es geschrieben hast ist es ein "Vergleich". Entweder so wie mein Beispielcode. Oder ohne &-Verknüpfungen, z.B. strhtml = Range("A9").Value & Range("B9").Value &  Range("C9").Value & Range("D9").Value & " <br>"
Vielen Dank! Das funktioniert. Da bin ich sehr glücklich mit  23