Ich bin VBA Einsteiger. Ich habe eine Excel Arbeitsmappe. Wenn dort in Spalte 19 ein x steht, soll an die Mailadresse aus Spalte 18 eine Mail versendet werden. Das ist in jeder Zeile eine andere Adresse und es soll auch jede Mail einzeln versendet werden.
Ich habe untenstehenden Code gebastelt, aber es funktioniert nicht. Kann mir jemand helfen, was der Fehler ist? Meist kommt der Fehler Error Object.
Sub Mailversand()
Dim Mappe_Aufruf As Workbook
Set Mappe_Aufruf = Active Workbook
Dim collAdresses As Collection
Set collAdresses = New Collection
Dim objOutlook As Object
Dim objMail As Object
Dim sEMail_Address As String
Dim iRow As Integer
Set objOutlook =
CreateObject("Outllok.Application")
Set objMail = objOutlook.CreateItem(0)
For iRow = 2 To 20
If Cells(iRow, 19) = "x" Then
sEMail_Address = Cells(iRow, 18)
'
If Contians(collAddresses,
sEmail_Address) Then
sEMail_Address = ""
End If
Dim recipient As recipient
If sEMail_Address ""Then
Set recipient " objEmail.Recipients.Add("sEmail_Address")
recipient.Type = oITo
End If
End If
Next
With objMail
.To = ""
.Subject = "Test"
.Body = "Test"
.CC = "examplemail"
.Display
End With
End Sub
Public Function Contains(coll As Collection, elem As Variant) As Boolean
Dim i As Integer
For i = 1 To coll.Count
If elem = coll(i) Then
Contains = True
Exit Function
End If
Next 'i = 1 To coll. Count
Contains = False
End Function