Na 14 pagina's te hebben doorgespit en de site van Ron De Bruin te hebben doorgenomen kan ik het nog niet vinden, mijn probleem:
Ik wil het werkboek mailen naar het mail adres staat dat in een cel staat, dit kan volgens mij met SendMail, maar aangezien ik een tekst moet kunnen verzenden (dus niet alleen subject) moet het anders, helaas kan ik nergens vinden hoe.
Ik gebruik nu de volgende code:
Ik wil het werkboek mailen naar het mail adres staat dat in een cel staat, dit kan volgens mij met SendMail, maar aangezien ik een tekst moet kunnen verzenden (dus niet alleen subject) moet het anders, helaas kan ik nergens vinden hoe.
Ik gebruik nu de volgende code:
Code:
Private Sub CommandButton2_Click()
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim OutApp As Object
Dim OutMail As Object
Set wb1 = ActiveWorkbook
If Val(Application.Version) >= 12 Then
If wb1.FileFormat = 51 And wb1.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will be no VBA code in the file you send." & vbNewLine & _
"Save the file first as xlsm and then try the macro again.", vbInformation
Exit Sub
End If
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
TempFilePath = Environ$("temp") & "\"
TempFileName = wb1.Name
FileExtStr = "." & LCase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))
wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set wb2 = Workbooks.Open(TempFilePath & TempFileName & FileExtStr)
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "max@mail.nl"
.CC = ""
.BCC = ""
.Subject = "Excel"
.Body = "Hallo, hierbij het bestand."
.Attachments.Add wb2.FullName
.Send 'or use .Display
End With
On Error GoTo 0
wb2.Close SaveChanges:=False
'Delete the file
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub