Ich habe ein Makro erstellt, um automatisierte E-Mails zu senden.Fehler beim Anhängen der nicht gespeicherten Arbeitsmappe
Es liegt ein Fehler mit dem Anhang vor. Ich erstelle den Anhang selbst.
Was ich als Anhang möchte, ist das Arbeitsblatt ws1, das, vom Lesen in Blogs, eine ganze Arbeitsmappe (Datei) als Anhang sein sollte.
Ich speichere die von mir erstellte Arbeitsmappe nicht. Ich möchte, dass die erstellte Arbeitsmappe gelöscht wird, nachdem ich die E-Mails gesendet habe, das ist der Grund für das Stück Code am Ende.
Sub EmailsNewReport()
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim ws1 As Worksheet
Dim wb As Workbook
Dim ws2 As Worksheet
Set ws1 = ThisWorkbook.Worksheets("New Report")
Set wb = Workbooks.Add
Set ws2 = wb.Worksheets(1)
ws1.Cells.Copy
With ws2
.Cells.PasteSpecial xlValues
.Cells.PasteSpecial xlFormats
End With
ws1.Activate
ToArray = "[email protected]"
Subject = "Hello"
Content = "Hey"
ws1.Range("B3:P31").Select
ActiveWorkbook.EnvelopeVisible = True
With Sheets("New Report").MailEnvelope
.Introduction = Content
.Item.To = ToArray
.Item.Subject = Subject
.Item.attachments.Add (wb.FullName)
.Item.Send
End With
Application.DisplayAlerts = False
ws2.Parent.Close False
Set ws2 = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub