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
Ist das nicht eine Methode nennen, erfordern einen parameter, nicht einem Auftrag. Anstatt also x = y, dessen x - (y): msdn.microsoft.com/en-us/library/office/ff869553.aspx
Genial! Das klappte auch, aber jetzt im .BodyFormat = olFormatHTML Zeile bekomme ich Run-time error '5': Ungültiger Prozeduraufruf oder ungültiges argument
Deklarieren 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 440
Debug-Zeile und sehen, was ist der Wert von subject zum Zeitpunkt des Fehlers?

InformationsquelleAutor Adjit | 2013-11-11

Schreibe einen Kommentar