Omer has attended:
Excel VBA Intro Intermediate course
Attaching a excel file to outlook email
Hi there, wondered if anyone can help me
I am trying to attach a excel file into an email (via Outlook)
Can you someone help? vba goes through the code creating the email and contents but cannot seem to attach the file. I get a runtime error, cannot find this file, verify the path and file name are correct - I am not sure what I doing wrong.
Many thanks,
Omer
Dim et As String
et = Application.InputBox("Please enter month end date to save as (DO NOT USE '\'): ""dd-mm-yy""")
Dim Newfile As String
Newfile = "AUM as of " & et & ".xls"
ChDir "Y:\FIMGroup\AUM"
ThisWorkbook.SaveAs Filename:=Newfile
Dim emailobj As Object
Dim email As Object
Dim varrecip As Variant
Dim varattach As Variant
Set emailobj = CreateObject("outlook.application")
Set objmail = emailobj.createitem(olmailitem)
objmail.display
objmail.Subject = "AUM Figures"
objmail.Recipients.Add "bbc1@com "
objmail.cc = "bbc@com;
objmail.body = "Dear All" & Chr(10) & Chr(10) & "Please find attached latest AUM data" & Chr(10) & Chr(10) & Chr(10) & Chr(10) & Chr(10) & Chr(10) & "Best regards" & Chr(10) & Chr(10) & "Omer"
objmail.attachments.Add "Y:\FIMGroup\AUM" & Newfile
End Sub
RE: Attaching a excel file to outlook email
Hi
Thanks for getting in touch. I haven't tested this code but the first thing that leaps out at me is the line where the filepath is setup:
ChDir "Y:\FIMGroup\AUM"
I think this needs a trailing slash at the end, i.e.
ChDir "Y:\FIMGroup\AUM\"
Try that and let me know how you get on.
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector