ungefähr so
Dim objCal As Object
Dim objOL As Object
Dim outl, mail As Object
Set outl = CreateObject("Outlook.Application")
Set objCal = objOL.GetNamespace("MAPI").GetDefaultFolder(9)
Set mail = outl.CreateItem(0)
mail.Subject = "dein Betreff"
mail.To = "Empfänger Email Adresse"
mail.Importance = 2
'Standardtext
mail.body = "Hallo!" 'Mailtext
'Eine Datei auf Laufwerk D:\ als Anhang mitsenden...
mail.Attachments.Add "C:\Temp\deineDatei"
'oder: die aktive Exceldatei als Anhang mitsenden...
'Mail.Attachments.Add ThisWorkbook.FullName
'Mail anzeigenMsgBox
mail.DISPLAY
'Ein sofortiger Mail-Versand geht in Firmen wegen Sicherheitseinstellungen oft nicht:
'Mail.Send
'aber es gibt eine Lösung mit SendKeys per Windows Scripting Host (Verweis ins VB-Projekt einfügen!):
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.AppActivate mail
'Sendet ein "Alt-S", Outlook sendet Mail sofort ohne Sicherheitsabfrage:
WshShell.SendKeys ("%s")
Set mail = Nothing
Set outl = Nothing
Set WshShell = Nothing
MsgBox ("Email erfolgreich versendet")
End Sub
|