Results 1 to 14 of 14

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

Threaded View

  1. #1
    Registered User
    Join Date
    11-04-2014
    Location
    Paris
    MS-Off Ver
    2010
    Posts
    8

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

    Hello everyone,

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

    I'm pretty sure that everyone gets it. 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)
    Here is the code:
    Private Sub btnSendEmail_Click()
        
        Dim MAIL As New Message
        Dim config As Configuration
        Set config = MAIL.Configuration
        
        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("MAIL", "A5:I56", "image")
        tempfilepath = Environ$("temp") & "\"
            MAIL.AddAttachment tempfilepath & "image.jpg", olbyvalue, 1
                
        MAIL.To = Range("N18").Text
        MAIL.CC = Range("N19").Text
        MAIL.From = config(cdoSendUserName)
        MAIL.Subject = "text" + Range("E21").Text + " text // " + Range("N8").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>Hello,</p>"
        
        MAIL.AddAttachment (Sheets("MAIL").Range("N17").Text)
        
        On Error Resume Next
        
        If MsgBox("Do you really want to send this email?", vbYesNo) = vbNo Then Exit Sub
        
        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
    Last edited by JBeaucaire; 11-04-2014 at 11:40 AM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Range("A1") = Sheets("Sheet2").CenterHeader.Text doesnt work.
    By HerryMarkowitz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2013, 07:06 AM
  2. Replies: 0
    Last Post: 11-20-2012, 10:22 AM
  3. Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",False)" not working
    By redders in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2011, 03:52 PM
  4. "Send to Mail Recipient" icon not working
    By Lynde in forum Excel General
    Replies: 7
    Last Post: 06-23-2005, 12:05 PM
  5. Sending macro based e-mail with built-in "Heading" and "Text"
    By Prabha in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2005, 11:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1