attaching excel file outlook

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Attaching a excel file to outlook email

Attaching a excel file to outlook email

resolvedResolved · High Priority · Version 2010

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

RE: Attaching a excel file to outlook email

Many thanks worked perfectly!!!
Thank you!!

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Create own ribbon tab - Excel 2010

a. In Excel click on the File tab
b. Select Options from left hand side
c. Choose the Customize Ribbon section
d. Click the New Tab button (below the list of tabs on the right hand side of the dialog box)
e. Select the New Tab (Custom) and enter a name, by clicking the Rename button (below the list of tabs on the right hand side of the dialog box)
f. Select the New Group (Custom) and enter a name, by clicking the Rename button (below the list of tabs on the right hand side of the dialog box)
g. Add commands to your tab and group by locating them on the list on the right hand side (remembering that you can change the list using the drop down box at the top of the list of commands) and clicking the Add button between the two panes to add them to your tab and group
h. You can rearrange the commands in your group, the groups on any tab or the tabs, using the up and down arrow buttons beside the list of tabs.
i. Click OK to apply your changes

View all Excel hints and tips


Server loaded in 0.08 secs.