You need to move this up above the code that's meant to create the PDF.
fn = "H:\AA - XXX\XX\XX\XX" & Format(Now(), "DD-MM-YYYY") & ".pdf"
Another couple of things you'll need to do is move this up to,
Set rng = ActiveSheet.Range("B8:J75")
and change the code that creates the PDF to this.
rng.ExportAsFixedFormat xlTypePDF, fn, OpenAfterPublish:=False
So after all those changes you should end up with this.
Option Explicit
Sub Mail_Genius()
Dim rng As Range
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
Dim fn As String
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set rng = ActiveSheet.Range("B8:J75")
fn = "H:\AA - XXX\XX\XX\XX" & Format(Now(), "DD-MM-YYYY") & ".pdf"
rng.ExportAsFixedFormat xlTypePDF, fn, OpenAfterPublish:=False
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = Range("d6").Value & " , " & Range("C18").Value & " , " & Range("B2").Value
.Attachments.Add fn
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Bookmarks