Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Excel Attache File

Excel Attache File

Excel Attache File

Hi All, Sorry I am very new to this stuff and normally just pinch all my Excel code from the net. I have a very basic script working to send an email and attach a file pasted in below. When I add the file path and name directly to the code (as per the line that is commented out) it works fine but if I add it as a reference to a cell name it will not work. I guess I am doing something basic wrong but I have no idea why. The objMailItem.Subject references a cell in the file and it works perfectly.

Sub SendEmail()

Dim objOutl
Set objOutl = CreateObject("Outlook.Application")
Set objMailItem = objOutl.CreateItem(olMailItem)
strEmailAddr = "info@u2.com.au"
objMailItem.Recipients.Add strEmailAddr
objMailItem.Subject = Range("Calcs!C16")
objMailItem.Body = "Hi"
'objMailItem.Attachments.Add "C:\Macro Test File.xlsx"
objMailItem.Attachments.Add = Range("Calcs!J7")
Set objMailItem = Nothing
Set objOutl = Nothing

RE: Excel Attache File

Because of the spaces in the file name, you may need to:

objMailItem.Attachments.Add '"'+ ALLTRIM(mFileName)+'"'

Just a quick thought.

RE: Excel Attache File

?? Are you talking to me? Or the poster? You should make that clear when making such a post. I have been programming FoxPro for 29 years. Don't know anything about VB.

RE: Excel Attache File

Thanks Mike Lewis, this is my first time in any forum so happy to accept your advice. I managed to find a solution so all good anyway.

RE: Excel Attache File


?? Are you talking to me? Or the poster?

Sorry for any confusion, but I would have thought it was obvious that I was talking to the OP. Why would somebody who posted a reply to a question be accused of doing so in the wrong forum?


Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close