Hinzufügen mehrerer Anhänge mit einer E-Mail mit outlook-VBA
BEARBEITEN
Sub CreateEmail(Subject As String, Body As String, ToSend As String, CCs As String, FilePathtoAdd As String)
Dim OlApp As Object
Dim OlMail As MailItem
Dim ToRecipient As Variant
Dim CcRecipient As Variant
Dim Attachments() As String
Dim i As Integer
Set OlApp = Application
Set OlMail = OlApp.CreateItem(olMailItem)
OlMail.Recipients.Add ToSend
OlMail.Subject = Subject
OlMail.Body = Body
OlMail.SentOnBehalfOfName = "mailbox"
If FilePath1 <> "" Then
If FilePathtoAdd <> "" Then
Attachments = Split(FilePathtoAdd, ",")
For i = LBound(Attachments) To UBound(Attachments)
If Attachments(i) <> "" Then
OMail.Attachments.Add Trim(Attachments(i))
End If
Next i
End If
End If
OlMail.Display 'change this to OlMail.Send if you just want to send it without previewing it
End Sub
Sub EmailIt()
CreateEmail "This is Subject", "Body", "To", "CC", "C:\Users\b\Desktop\NFM\Export\0418 LSN " & Format(Date, "mm-dd-yy") & ".xls", "C:\Users\b\Desktop\NFM\Export\0418 Backorder " & Format(Date, "mm-dd-yy") & ".xls"
End Sub
Ich bin mit dem folgenden code in der outlook-vba, erstellen einer E-Mail eine Datei Anhängen und senden Sie die E-Mail. Es funktioniert gut, außer ich kann nicht herausfinden, wie Sie mehrere Anhänge mit einer E-Mail? Jede Hilfe wird sehr geschätzt.
Sub CreateEmail(Subject As String, Body As String, ToSend As String, CCs As String, FilePathtoAdd As String)
'write the default Outlook contact name list to the active worksheet
Dim OlApp As Object
Dim OlMail As MailItem
Dim ToRecipient As Variant
Dim CcRecipient As Variant
'Set OlApp = CreateObject("Outlook.Application")
'Set OlMail = OlApp.CreateItem(olMailItem)
Set OlApp = Application
Set OlMail = OlApp.CreateItem(olMailItem)
'For Each ToRecipient In Array("[email protected]", "[email protected]", "[email protected]")
'OlMail.Recipients.Add ToRecipient
OlMail.Recipients.Add ToSend
'Next ToRecipient
'fill in Subject field
OlMail.Subject = Subject
OlMail.Body = Body
OlMail.SentOnBehalfOfName = "email.com"
'Add the active workbook as an attachment
' OlMail.Attachments.Add "C:\Users\Ali\Desktop\Sentence Correction\Comparisons.pdf"
If FilePathtoAdd <> "" Then
OlMail.Attachments.Add FilePathtoAdd
End If
'Display the message
OlMail.Display 'change this to OlMail.Send if you just want to send it without previewing it
End Sub
Sub EmailIt()
CreateEmail "This is Subject", "Body", "email.com", " ", "C:\Users\b\Desktop\NFM\Export\0418 LSN " & Format(Date, "mm-dd-yy") & ".xls"
End Sub
- Bereits gestellt und hier beantwortet: Befestigen Sie die zwei Dateien in einer E-mail
InformationsquelleAutor WeathermanJB | 2015-03-19
Schreibe einen Kommentar Antworten abbrechen
Du musst angemeldet sein, um einen Kommentar abzugeben.
Sie müssen nur zu tun:
Wenn du die Anlage Pfade in einer durch Trennzeichen getrennte Zeichenfolge und übergeben Sie es als "FilePathToAdd", dann können Sie dies tun:
OMail.Attachments.Add Trim(Attachments(i))
aber der Dateipfad ist korrekt und die Datei ist da. Meine "filepathtoadd" string"C:\Users\balljt\Desktop\NFM\Export\0418 LSN " & Format(Date, "mm-dd-yy") & ".xls, C:\Users\balljt\Desktop\NFM\Export\0418 Backorder " & Format(Date, "mm-dd-yy") & ".xls"
Vielleicht das Datum im format werfen?OlMail.Attachments.Add FilePathtoAdd
undC:\Users\balljt\Desktop\NFM\Export\0418 LSN " & Format(Date, "mm-dd-yy") & ".xls"
Die folgenden Zeilen aus dem code hinzufügen, der Befestigung:
Brauchen Sie nur zu rufen, der Hinzufügen Methode der Befestigung der Klasse, so oft wie Sie benötigen, um die Anlagen hinzufügen, wenn Sie unterschiedliche Datei-Pfade.