Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Attache File

Status
Not open for further replies.

Mick AOL

Technical User
Nov 25, 2019
2
AU
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)
objMailItem.Display
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
 
Because of the spaces in the file name, you may need to:

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

Just a quick thought.
 
?? 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.
 
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.
 
?? 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

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top