Hi,
This one has been bugging me for a while - I am hoping somebody will be able to help.
I have been using the following code:
Which is an alteration to some code i found on Spreadsheet Guru.
I have managed in the most part to get it to work - except the name of the actual PDF document that gets attached to the email. I dont want this to be the Workbook name & then date in A4. I just want it to be named as per what is in Cell A4 (.pdf).
I have tried fiddling with it, but whenever i do, i just get a debug error, that highlights the .Attachments.Add PdfFile
I would really appreciate some assistance?
cheers
This one has been bugging me for a while - I am hoping somebody will be able to help.
I have been using the following code:
Code:
Sub EmailPDFPaymentNotice()
Application.ScreenUpdating = False
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object, signature As String
Dim Filename As String
' Define Email subject line
Title = Range("A4").Value
' Define PDF filename
PdfFile = ActiveWorkbook.FullName
Filename = Range("A4").Value
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & Filename & ".pdf"
'PdfFile = FileName & ".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
Set OutlMail = OutlApp.CreateItem(0)
' Prepare e-mail with PDF attachment
With OutlMail
' Prepare e-mail
.Subject = Title
.To = Range("M37").Value ' <-- Put email of the recipient here
' .CC = "..." ' <-- Put email of 'copy to' recipient here
.Body = Range("D37").Value & "," & vbLf & vbLf _
& "Please find attached Payment Notice Nr " & Range("O5").Value & " with reference to your works at " & Range("C6").Value & "." & vbLf & vbLf
'& Application.DefaultSaveFormat & vbLf & vbLf
.Attachments.Add PdfFile
' Try to send (display)
On Error Resume Next
.Display
'.Send
'Application.Visible = True
'If Err Then
' MsgBox "E-mail was not sent", vbExclamation
'Else
' MsgBox "E-mail successfully sent", vbInformation
'End If
'On Error GoTo 0
End With
' Delete PDF file
Kill PdfFile
' Quit Outlook if it was created by this code
' If IsCreated Then OutlApp.Quit
' Release the memory of object variable
' Set OutlApp = Nothing
Application.ScreenUpdating = True
MenuFull.Hide
End Sub
Which is an alteration to some code i found on Spreadsheet Guru.
I have managed in the most part to get it to work - except the name of the actual PDF document that gets attached to the email. I dont want this to be the Workbook name & then date in A4. I just want it to be named as per what is in Cell A4 (.pdf).
I have tried fiddling with it, but whenever i do, i just get a debug error, that highlights the .Attachments.Add PdfFile
I would really appreciate some assistance?
cheers
Last edited by a moderator: