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

attaching excel file outlook

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

ResolvedVersion 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:

Sum Up All the Values in A Column

If you want to quickly calculate the Summed values of all cells in a column in Excel 2003 normally you would use the SUM formula. (eg if you wanted to calculate the values in Column C rows 10 to 25) the formula would be:

=SUM(C10:C25)

However, if you keep adding values to column C you would keep having to modify the above SUM formula which can get quite annoying.

To get around this you can sum all the values in a column using the following formula:

=SUM(COLUMN:COLUMN)

Which, in our example, would be:

=SUM(C:C)

NOTE You cannot place this formula in column C, or else Excel 2003 will show a circular reference error.

The formula must be placed in any other column, EXCEPT the one being calculated.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.