Goedemiddag,
Ik heb een code in excel staan die een excel blad opslaat als PDF en daarna per mail verzend,
Nu wil ik er graag nog 1 of 2 andere bijlagen handmatig aan toevoegen aan de mail,
Dus de code moet alles doen behalve verzenden - dus wel mail aanmaken en klaarzetten.
Deze code heb ik - wat moet ik aan het eind wijzigen?
Sub SendWorkSheetToPDF()
Dim Wb As Workbook
Dim FileName As String
Dim OutlookApp As Object
Dim OutlookMail As Object
On Error Resume Next
Set Wb = Application.ActiveWorkbook
FileName = Wb.FullName
xIndex = VBA.InStrRev(FileName, ".")
If xIndex > 1 Then FileName = VBA.Left(FileName, xIndex - 1)
FileName = FileName & "_" + ActiveSheet.Name & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
With OutlookMail
.To = Range("J1").Value 'mailadres in cel excel
.CC = ""
.BCC = ""
.Subject = "uren briefje"
.Body = "Hierbij het uren briefje - gaarne nakijken of dit klopt."
.Attachments.Add FileName
.Send
End With
Kill FileName
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
Ik heb een code in excel staan die een excel blad opslaat als PDF en daarna per mail verzend,
Nu wil ik er graag nog 1 of 2 andere bijlagen handmatig aan toevoegen aan de mail,
Dus de code moet alles doen behalve verzenden - dus wel mail aanmaken en klaarzetten.
Deze code heb ik - wat moet ik aan het eind wijzigen?
Sub SendWorkSheetToPDF()
Dim Wb As Workbook
Dim FileName As String
Dim OutlookApp As Object
Dim OutlookMail As Object
On Error Resume Next
Set Wb = Application.ActiveWorkbook
FileName = Wb.FullName
xIndex = VBA.InStrRev(FileName, ".")
If xIndex > 1 Then FileName = VBA.Left(FileName, xIndex - 1)
FileName = FileName & "_" + ActiveSheet.Name & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
With OutlookMail
.To = Range("J1").Value 'mailadres in cel excel
.CC = ""
.BCC = ""
.Subject = "uren briefje"
.Body = "Hierbij het uren briefje - gaarne nakijken of dit klopt."
.Attachments.Add FileName
.Send
End With
Kill FileName
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub