trotz Suchen und ausprobieren bekomme ich mein Makro nicht zum Laufen und bitte um Hilfe.
Durch das Makro wird eine E-Mail mit Anhang generiert.
Als Anhang wird automatisch 1 Tabellenblatt aus der Excel-Mappe kopiert.
Ich möchte, dass der E-Mail-Anhang nicht den Namen des Tabellenblatts ("Eingabe") trägt.
Es wäre klasse, wenn der Anhang den Namen der Ursprungsdatei hätte.
Vielen Dank vorab.
Gruß
Raphael
Private Sub CommandButton1_Click()
Dim xOutApp As Object
Dim xOutMail As Object
Dim strBlatt As String
Dim strDatei As String
Dim strPfad As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
'** Pfad für temporäre Zwischenspeicherung angeben
strPfad = "C:\Temp" 'entsprechend anpassen
Worksheets(Array("Eingabe")).Copy
Application.DisplayAlerts = False
'** Blatt temporär in vorgegebenes Verzeichnis abspeichern
ActiveWorkbook.SaveAs strPfad & "\" & ActiveSheet.Name
Application.DisplayAlerts = True
'** Pfad und Dateiname der neuen Datei zwischenspeichern
strDatei = ActiveWorkbook.FullName
With xOutMail
.GetInspector
.To = ""
.CC = ""
.BCC = ""
.Subject = ""
.Attachments.Add strDatei
.HTMLBody = "" & _
"Guten Tag,
" & _
"anbei sende ich euch ...." & .HTMLBody
.Display 'or use .Send
End With
'** Erzeugte Datei schließen
Workbooks(Dir(strDatei)).Close
'** Erzeugte Datei wieder löschen
Kill (strDatei)
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub