Excel-VBA Versenden von E-Mails mit mehreren Geräten
So halten wir diese große Veranstaltung und ich habe ein excel-Blatt mit jedermanns Namen, E-Mail-Adresse sowie Ihre Reiseroute Dateien (es gibt 2 davon) Cells(x, 3)
und Cells(x, 4)
. Was ich versuche zu tun ist, gehen Sie die Spalte und senden Sie jeder eine "persönliche" E-Mail mit all Ihren Informationen.
In den code, der for
Schleife geht nur bis 3, weil ich nur testen Sie es durch Versand der E-Mails an mich selbst und möchte nicht am Ende immer 1000 E-Mails 😛
Bekomme ich immer eine Run-Time Error 440 (Automatisierungsfehler) bei den Zeilen, wo ich versuche, fügen Sie die Anlagen... nicht sicher, was Los ist, oder wie um es zu beheben jede Hilfe ist willkommen
Code
Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.
Dim olApp As Object
Dim objMail As Object
Dim body, head, filePath, subject As String
Dim x As Long
Set olApp = CreateObject("Outlook.Application")
'Create e-mail item
Set objMail = olApp.CreateItem(0)
filePath = "\\fileserver\homeshares\Tsee\My Documents\Metropolitan Sales\MNF"
subject = "Important Travel Information for MNF Event this weekend"
x = 1
For x = 1 To 3
head = "<HTML><BODY><P>Hi " & Cells(x, 1).Value & ",</P>"
body = body & "<BR /><P>We are looking forward to having you at our <STRONG>Metropolitan Night Football Event</STRONG> this upcoming Sunday, <STRONG>11/17</STRONG>! Note, that the Giants game time has changed from 8:30 PM to 4:25 PM.</P>"
body = body & "<BR /><P>Please find attached your travel information packet that contains important addresses and confirmation numbers. Please read through it and let me know if you have any questions.</P>"
body = body & "<BR /><P>If you need to reach me this weekend, please call my cell phone <STRONG>(631) 793-9047</STRONG> or email me.</P>"
body = body & "<BR /><P>Thanks,<BR />Liz</P></BODY></HTML>"
With objMail
.subject = subject
.To = Cells(x, 2).Value
.Attachments.Add = filePath & "/" & Cells(x, 3).Value
.Attachments.Add = filePath & "/" & Cells(x, 4).Value
.BodyFormat = olFormatHTML
.HTMLBody = head & body
.Send
End With
Next x
End Sub
Genial! Das klappte auch, aber jetzt im
.BodyFormat = olFormatHTML
Zeile bekomme ich Run-time error '5': Ungültiger Prozeduraufruf oder ungültiges argumentDeklarieren Sie diese oben in deinem code
Const olFormatHTML = 2
oder ersetzen .BodyFormat = olFormatHTML
durch .BodyFormat = 2
So, das funktioniert, aber jetzt bekomme ich eine verrückte Automatisierung Fehler... geht es durch die Schleife einmal.. sendet 1 E-Mail und dann wenn es wird bis zu
.subject = subject
ich bekommen, Run-time error '-2147221238 (8004010a)': Automation Error das, so weit ich weiß, ist das gleiche wie Run-Time Error 440Debug-Zeile und sehen, was ist der Wert von
subject
zum Zeitpunkt des Fehlers?InformationsquelleAutor Adjit | 2013-11-11
Du musst angemeldet sein, um einen Kommentar abzugeben.
Weiter oben Kommentare, @bamie9l hat sich bereits gelöst, ein problem von Ihnen
Problem 2
Sind Sie späte Bindung mit Outlook von Excel-und
olFormatHTML
ist ein Outlook-Konstante und damit Excel nicht in der Lage ist, es zu erkennen. In derImmediate Window
von MS-Outlook, wenn Sie Typ?olFormatHTML
dann werden Sie feststellen, dass der Wert dieser Konstante ist2
Daher müssen wir erklären, dass Konstanten in Excel. Wie ich bereits erwähnt habe, entweder Sie können
Const olFormatHTML = 2
an der Spitze des code oder ersetzen.BodyFormat = olFormatHTML
durch.BodyFormat = 2
Problem 3
Das problem ist, dass Sie das anlegen des outlook-Element außerhalb der Schleife durch
Outlook bereits an, dass E-Mail und jetzt für den nächsten E-Mail werden Sie haben, um neu zu erstellen. So verschieben, dass die Linie innerhalb der Schleife.
Froh, dass es geklappt 🙂
InformationsquelleAutor Siddharth Rout