in meinem Workbook "VERSAND", in Tabelle "Auflistung" habe ich in Spalte A ab Zeile 3 die Pfade und in Spalte B ab Zeile 3 die Namen (von geschlossenen) .xls Dateien aufgeführt. Nun möchte ich diese per Mail versenden. Da die Dateien eine gewisse Grösse haben, möchte ich pro Mail nur 5 Dateien versenden.
Bisher habe ich nur offene Excel-Files versandt und pro Mail immer nur eine Datei. Ich bin sehr dankbar für Hinweise, wie ich nachfolgenden Code umbauen muss, dass eine solche Aufbereitung von Mails möglich wird.
Vielen Dank, Peter
Sub senden()
Dim Nachricht As Object, OutApp As Object
Dim SavePath As String
Dim AWS As String
Dim File As String
Dim vFile as String
Dim to_ As String
ThisWorkbook.Activate
to_ = Sheets("Parameter").Range("Versand")
vFile = ActiveSheet.Name
SavePath = Application.ActiveWorkbook.path
File = ActiveSheet.Name
ActiveSheet.Copy 'Kopiert aktuelles Sheet in eine neue Mappe
With ActiveWorkbook
.Sheets(1).Name = "Print"
.SaveAs SavePath & "\" & File
End With
With ActiveWorkbook
.Save
End With
'Aktive Arbeitsmappe wird als mail gesendet
AWS = ActiveWorkbook.FullName
Application.DisplayAlerts = False
Set OutApp = CreateObject("Outlook.Application")
'InitializeOutlook = True
Set Nachricht = OutApp.CreateItem(0)
With Nachricht
.To = to_
.Subject = "Report " & Date & " " & Time
.Attachments.Add AWS
.Display
End With
Set OutApp = Nothing
Set Nachricht = Nothing
Application.DisplayAlerts = True
ActiveWorkbook.Close
Kill AWS
End Sub