cdo email attachment

Dave199

New Member
Joined
Dec 3, 2014
Messages
2
Hello All,

I would like to than everyone in advance as the information I have gathered and things I have learnt from the Mr Excel forums make me look like a genius at work.
I now have a problem with trying to attached a file to an email using vba and cdo.
When I type the file location into the code it works fine, when I try and link a cell with the file location to the code it wont work.
Thanks again in advance.
Dave

Sub CommandButton10_Click()
Dim Mail As New Message
Dim Config As Configuration
Set Config = Mail.Configuration
Dim cell As Range
Dim strbody As String
For Each cell In Sheets("Time Card Data").Range("ah2:ah6")
strbody = strbody & cell.Value & vbNewLine
Next


Config(cdoSendUsingMethod) = cdoSendUsingPort
Config(cdoSMTPServer) = "smtp.gmail.com"
Config(cdoSMTPServerPort) = 25
Config(cdoSMTPAuthenticate) = cdoBasic
Config(cdoSMTPUseSSL) = True
Config(cdoSendUserName) = "excel.email.cel@gmail.com"
Config(cdoSendPassword) = "celmec2014"
Config.Fields.Update


Mail.To = Sheets("Time Card Data").Range("v20").Value
Mail.From = Config(cdoSendUserName)
Mail.Subject = Sheets("Time Card Data").Range("ah7").Value
Mail.TextBody = strbody
Mail.AddAttachment = Sheets("Time Card Data").Range("ah10").Value


On Error Resume Next


Mail.Send


If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "There was an error"
Exit Sub
End If
MsgBox "Your email has been send!", vbInformation, "Sent"


End Sub
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I thought this might be useful, this is the contents of the cell I am trying to link to,
[TABLE="width: 611"]
<tbody>[TR]
[TD="width: 611"]"file:///Z:\Time%20Sheets\CSV%20Files\Celmec%20Timesheet%20Factory%20WE%2002-12-14.csv"

when I paste that into the code it works fine.[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top