Live-Forum - Die aktuellen Beiträge
Datum
Titel
28.03.2024 21:12:36
28.03.2024 18:31:49
Anzeige
Archiv - Navigation
1144to1148
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Emailtext mit Schleife bis Zelle leer

Emailtext mit Schleife bis Zelle leer
Gonzer
Hallo zusammen,
ich würde gerne automatisch eine EMail per Excel erstellen lassen, was auch funktioniert, und dabei den Emailtext variabel gestalten.
Heisst also eine Schleife einbauen bis in Spalte B kein Wert mehr enthalten ist:
Sub sendMail()
Dim OutApp As Object, OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = "Emailadresse"
.Subject = "Betreff"
.Body = Worksheets("Mappe1").Cells(1, 2) & vbLf & _
Worksheets("Mappe1").Cells(2, 2) & vbLf & _
'hier hätte ich gerne ein Schleife bis in Spalte B kein Wert mehr steht
'....   also z.B Spalte B enthält in Zeile 10 keinen Wert mehr dann wäre die  _
letzte Textzeile
Worksheets("Mappe1").Cells(9, 2) & vbLf & _
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

7
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Emailtext mit Schleife bis Zelle leer
11.03.2010 09:03:45
Renee
Hi Gonzer,
    Dim txtBody As String
Dim lngRow As Long
With Worksheets("Mappe1")
For lngRow = 1 To .Cells(.Rows.Count, 2).End(xlUp).Row
txtBody = txtBody & .Cells(lngRow, 2).Txt & vbLf
Next lngRow
End With
With OutMail
.to = "Emailadresse"
.Subject = "Betreff"
.Body = txtBody
...
GreetZ Renée
AW: Emailtext mit Schleife bis Zelle leer
11.03.2010 09:04:07
Josef

Hallo Gonzo,
das geht so.

Sub sendMail()
  Dim OutApp As Object, OutMail As Object
  Dim strBody As String, lngRow As Long
  
  With Worksheets("Mappe1")
    For lngRow = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row
      If .Cells(lngRow, 1) <> "" Then
        strBody = strBody & .Cells(lngRow, 1).Text & vbLf
      End If
    Next
  End With
  
  If Len(strBody) Then strBody = Left(strBody, Len(strBody) - 1)
  
  Set OutApp = CreateObject("Outlook.Application")
  OutApp.Session.Logon
  
  Set OutMail = OutApp.CreateItem(0)
  
  With OutMail
    .To = "Emailadresse"
    .Subject = "Betreff"
    .Body = strBody
    .Display
  End With
  
  Set OutMail = Nothing
  Set OutApp = Nothing
End Sub

Gruß Sepp

Anzeige
Sepp: ,2 statt ,1 ;-)) (owT)
11.03.2010 09:06:55
Renee

Aber Hallo!
11.03.2010 09:09:14
Josef

Guten Morgen Renee,
ich wollte ja nur testen, ob du schon wach bist;-)))
Danke!

Gruß Sepp

22 Sek. vor Dir wach ;-)) (owT)
11.03.2010 11:14:40
Renee

22 Sek. vor Dir wach ;-)) (owT)
11.03.2010 11:15:26
Renee

AW: Emailtext mit Schleife bis Zelle leer
11.03.2010 09:10:39
fcs
Hallo Gonzer,
du muss dann den gesamten Body-Text in einer Variablen generieren/speichern.
Gruß
Franz
Sub sendMail()
Dim OutApp As Object, OutMail As Object, strBody As String, Zeile As Long
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
strBody = Worksheets("Mappe1").Cells(1, 2) & vbLf & _
Worksheets("Mappe1").Cells(2, 2) & vbLf
Zeile = 3
Do Until Worksheets("Mappe1").Cells(Zeile, 2) = ""
strBody = strBody & Worksheets("Mappe1").Cells(Zeile, 2) & vbLf
Zeile = Zeile + 1
Loop
With OutMail
.To = "Emailadresse"
.Subject = "Betreff"
.Body = strBody
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub

Anzeige

315 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige