Hi all
I'm working on a workbook called "1282 Final" that when a "submit" button is pressed the vba code copies data to another sheet in the workbook, creates a pdf from the active worksheet, names the pdf in a very specific format, attaches the pdf to an email and then saves the pdf to the same folder path as where the "1282 Final" workbook is.
I'm really happy with how it all works but I'd like for when the pdf exports it saves in to a specific folder which has the path of "X:\Airfield Operations\2022 Airfield Inspection and Data\CA1282 Bird Strikes\PDF" rather than just where the workbook is. I do need the file name to be as the coding names it.......for example "1282 Final_Serial 28 - 27-11-2022"
I've attached the part of the vba code that refers to the creation of the pdf.... could anyone please help?
Thank you
I'm working on a workbook called "1282 Final" that when a "submit" button is pressed the vba code copies data to another sheet in the workbook, creates a pdf from the active worksheet, names the pdf in a very specific format, attaches the pdf to an email and then saves the pdf to the same folder path as where the "1282 Final" workbook is.
I'm really happy with how it all works but I'd like for when the pdf exports it saves in to a specific folder which has the path of "X:\Airfield Operations\2022 Airfield Inspection and Data\CA1282 Bird Strikes\PDF" rather than just where the workbook is. I do need the file name to be as the coding names it.......for example "1282 Final_Serial 28 - 27-11-2022"
I've attached the part of the vba code that refers to the creation of the pdf.... could anyone please help?
Thank you
VBA Code:
Sheets("Birdstrike").Select
'email and pdf
Dim IsCreated As Boolean
Dim I As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object
' Title area
Title = Range("C6")
' Define PDF filename
PdfFile = ActiveWorkbook.FullName
I = InStrRev(PdfFile, ".")
If I > 1 Then PdfFile = Left(PdfFile, I - 1)
PdfFile = PdfFile & "_Serial" & " " & Title & " - " & Format(Now(), "dd-mm-yyyy") & ".pdf"
' Export activesheet as PDF
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
' Use already open Outlook if possible
On Error Resume Next
Set OutlApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlApp = CreateObject("Outlook.Application")
IsCreated = True
End If
OutlApp.Visible = True
On Error GoTo 0
' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)
' E-mail address and content
.Subject = "1282 Bird Strike Form - Serial" & " " & Title & " - " & ActiveSheet.Range("F6")
.To = "fredbloggs@me.com" ' <-- Put email of the recipient here
.Body = "Hi Trevor," & vbLf & vbLf _
& "Please find attached a PDF of the 1282 for the recent Wildlife Strike Incident." & vbLf & vbLf _
& "Regards," & vbLf _
& Application.UserName & vbLf & vbLf
.Attachments.Add PdfFile
' Try to send
On Error Resume Next
.Display
Application.Visible = True
If Err Then
MsgBox "E-mail was not generated", vbExclamation
End If
On Error GoTo 0
End With
' Quit Outlook if it was created by this code
If IsCreated Then OutlApp.Quit
' Release the memory of object variable
Set OutlApp = Nothing