MAIL.AddAttachment (Sheets("MAIL").Range("N17").Text) <---- Why is it not working?

VBAzr

New Member
Joined
Oct 28, 2014
Messages
10
Hi everyone,

Just trying to send an email (gmail) using VBA CDO in excel and my problem is in the title.

I want my mail attachment to be selected in a specific cell (that is doing a Vlookup on a customer name) in one of my sheets:

MAIL.AddAttachment (Sheets("MAIL").Range("N17").Text)

Thanks a lot!

 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hi VBAzr,

If you have set MAIL as

Code:
set MAIL = CreateObject("CDO.Message")

then

Code:
MAIL.AddAttachment Sheets("MAIL").Range("N17").value


where cell N17 must be C:\username\CDO_Example.xlsm
 
Upvote 0
Hi vds1,

That's what I did... still not working. Here is the code:

____________________________________________________
Private Sub btnSendEmail_Click()

Dim MAIL As New Message
Dim config As Configuration
Set config = MAIL.Configuration
Set MAIL = CreateObject("CDO.Message")

config(cdoSendUsingMethod) = cdoSendUsingPort
config(cdoSMTPServer) = "smtp.gmail.com"
config(cdoSMTPServerPort) = 25
config(cdoSMTPAuthenticate) = cdoBasic
config(cdoSMTPUseSSL) = True
config(cdoSendUserName) = "email@email.com"
config(cdoSendPassword) = "password"
config.Fields.Update

Call createJpg("MAILDELAY.FR", "A1:I49", "INVOICE")
tempfilepath = Environ$("temp") & "\"
MAIL.AddAttachment tempfilepath & "INVOICE.jpg", olbyvalue, 1

MAIL.To = Range("N14").Text
MAIL.CC = Range("N15").Text
MAIL.From = config(cdoSendUserName)
MAIL.Subject = "Pénalité " + Range("E17").Text + " sur délai de livraison // " + Range("N4").Text
MAIL.HTMLBody = "<span LANG=FR><p class=style2 p align=justify p style='width='850' height='1500'><span LANG=FR><font FACE=Calibri SIZE=3>" & _
"<p>dear, blah blah blah...<p/>"

MAIL.AddAttachment Sheets("MAILDELAY.FR").Range("N17").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 sent", vbInformation, "sent"


End Sub
_______________________________________________________
Sub createJpg(Namesheet As String, nameRange As String, nameFile As String)
ThisWorkbook.Activate
Worksheets(Namesheet).Activate
Set Plage = ThisWorkbook.Worksheets(Namesheet).Range(nameRange)
Plage.CopyPicture
With ThisWorkbook.Worksheets(Namesheet).ChartObjects.Add(Plage.Left, Plage.Top, Plage.Width, Plage.Height)
.Activate
.Chart.Paste
.Chart.Export Environ$("temp") & "\" & nameFile & ".jpg", "JPG"
End With
Worksheets(Namesheet).ChartObjects(Worksheets(Namesheet).ChartObjects.Count).Delete
Set Plage = Nothing
End Sub
 
Upvote 0
Hi VBAzr,

Few questions for you ,

1) have you tried to open the file manually mentioned in c17? have you ensured the name and file path is accurate ?
2) Just curious to know what value you have in C17 at the moment? have you tried for a different file path and name ?
3) What is the error message ?

here is a good resource for you
Sending mail from Excel with CDO
 
Last edited:
Upvote 0
1) have you tried to open the file manually mentioned in c17? have you ensured the name and file path is accurate ?
Yes. And it works if I put it like that:
MAIL.AddAttachment "C:\thefilepath.pdf"

2) Just curious to know what value you have in C17 at the moment? have you tried for a different file path and name ?
It is the file path (from a Vlookup)

3) What is the error message ?
Run-time error '-2147024894 (80070002)':
file not found.

Thanks for the link!

 
Upvote 0
I really can't solve my problem... Even if I'm using the information in the linked you suggested me.
 
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