Hi All

I have a problem with adding an attachment to an email . It's been driving me mad for days.

I can create the email no problem but the email is just a part of a macro which saves a sheet from the workbook to pdf and sends it to a folder and then clears the form for the next entry. The problem I'm having as attaching the saved pdf to the email. I've tried every combination of address for the file imaginable without success to create the attachment. I've added the code to see if anyone can see where I'm going wrong. I've left my last attempt at the address in the .Attachments line for you to see

Kind regards

Paul

Option Explicit
    
Sub SaveAsPDF()
    'save OFGEM Report as pdf to OFGEM Report Folder
    Dim strFileName As String
    strFileName = "C:\Users\paulalexanderbreen\Desktop\OFGEM Reports\OFGEM Report " & Worksheets("OFGEM Report").Range("AE1").Value
    Worksheets("OFGEM Report").ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName _
        , Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
        :=False, OpenAfterPublish:=True
        
emailtoinfo

End Sub
    

Sub emailtoinfo()
'Declare and establish the object variables for Outlook.

Dim objOutlook As Object
Dim objNameSpace As Object
Dim objInbox As Object
Dim objMailItem As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objNameSpace = objOutlook.GetNamespace("MAPI")
Set objInbox = objNameSpace.Folders(1)
Set objMailItem = objOutlook.CreateItem(0)


'Activate or open Outlook.
On Error Resume Next
AppActivate ("Outlook")
If Err.Number <> 0 Then objInbox.Display
Err.Clear

'Create MailItem email object.
With objMailItem
.To = "info@solarswitching.com"
.Subject = "Ofgem Report: " & "  " & Worksheets("OFGEM Report").Range("AE1").Value
.Body = "Hi Carol" & vbCrLf & vbCrLf & "Please find attached Ofgem Report for " & Worksheets("OFGEM Report").Range("AE1").Value & vbCrLf & vbCrLf & "Kind Regards" & vbCrLf & vbCrLf & "Paul"
.Attachments.Add "C:\Users\paulalexanderbreen\Desktop\OFGEM Reports\OFGEM Report " & Worksheets("OFGEM Report") & Range("AE1").Value.xlTypePDF \ ""
.Display
End With

'Release object variables from system memory.
Set objOutlook = Nothing
Set objNameSpace = Nothing
Set objInbox = Nothing
Set objMailItem = Nothing

clearcontents

End Sub


Sub clearcontents()
    ' clear contents of input sheet
    Range("a3:bb3").clearcontents
End Sub