Insert a PDF document as an attachment to my e-mail

Maury1704

New Member
Joined
Jan 13, 2016
Messages
24
Hello everyone, my name is Maurizio
and my problem is this:
using the vba I created a procedure that opens my e-mail that sometimes does not have to be (Outlook) and I have already placed the address of the recipient in his place and so far so good.
Then I created a procedure that takes data from sheet1 and more precisely from cell (A11: L23) and creates a pdf document that inserts it into the subdirectory called (Utility) and here everything is OK.
Ahora my question and this: there would be the possibility to take the pdf document and insert it in the email as an attachment?
Thank you so much for all the help you want to give me. Thank you


Attach test file

Links : https://app.box.com/s/zidy0m003eejjjnxqd0q8k2bx9lq4srs
 

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
Hi yky Thank you for your tip
But as I see you as others, you have not looked at my program.
As otherwise
1) You would have noticed that I only need the code to tell the e-mail to attach the pdf file that is inside the Utility Folder.
2) In addition you would have noticed that I do not open the email with (OutLook) as do many of you (Programmers) but I open it with what is different from the existing OutLook in your PC.
That's all !
Anyway Thanks Anyway Greetings and Happy Weekends
 
Upvote 0
I did see that you had the following code. That's why I posted the link, which contained instructions for adding attachment in Outlook. I think it is something like .addattachment. I don't use Outlook. So, I may be wrong about it.

Code:
    Set otl = CreateObject("Outlook.Application")
    Set msg = otl.CreateItem(0)
    
    With msg
        .To = "prova@prova.it"
        .CC = "destinatariocc@prova.it"
        .Subject = "Oggetto"
        .HTMLBody = "messaggio HTML"

        .Display
    End With
 
Upvote 0
Hi yky
First of all, thanks for your suggestion.
Although to be honest I did not understand what I can serve.
2) Then again I do not want to work with OutLook but with E-mail windows 10 or with Thunderbird of mozilla
And my program does all this.
The problem arises when: Once you have created the PDF document that is inserted in the subfolder called work (Utility) should be taken via code and put as an attachment in the email that is opened; Whether it is, Windows 10 emails I have Mozilla's Thunderbird
While your suggestion does nothing of all this.
That's all. Thank you
 
Last edited:
Upvote 0
Check out the CDO instruction in the following page. You don't need to open Thunderbird. You compose the email, To:, From:, Subject:, mail body, etc. by code.

https://www.rondebruin.nl/win/s1/cdo.htm

To add attachment, add this line:

Code:
        .AddAttachment file_path & "\" & file_name

To add multiple attachments, repeat the .AddAttachment for each attachment.
 
Last edited:
Upvote 0
Hi yky
Thank you once again for your support and your patience and commitment that you have dedicated to me.
I tried in every way possible to me
But without your direct support I would not know how to come out because: I just can not put this blessed document as an attachment.
I followed the instructions of the link you gave me, but continue to give me error on (.Send) and I do not understand why.
Patience will mean that I will continue to insert an attachment by hand, also because I repeat I could not do otherwise.
Hello and many thanks for your commitment
 
Upvote 0
I use the same CDO code from the same page with some modification. So, I'm sure it works. Please post your code but hide the email account and password.
 
Upvote 0
I haven't read your code. Below is my code for CDO mail. I just noticed that I made a note saying if the file is open, you can send it as attachment. It must be closed first. Maybe that's your problem.

Code:
Public Sub CDO_Mail()

    'this script can only send closed files. it cannot send open files.
    'close open files first if you want to send them.
    'If you get this error : The transport failed to connect to the server
    'then try to change the SMTP port from 25 to 465

    Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    Dim Flds As Variant
    Dim wb As Workbook
    Dim Report_Date As String
    
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    On Error Resume Next

    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "mygmailaccount@gmail.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.googlemail.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
        .Update
    End With

    strbody = "Dear Sir," & vbNewLine & vbNewLine & _
        "Attached please find the report I promised to send you " & _
       vbNewLine & vbNewLine & "--" & vbNewLine & _
        "Best Regards," & vbNewLine & vbNewLine & vbNewLine & vbNewLine & _
        "Yours Truly" & vbNewLine & vbNewLine
          
 
    With iMsg
        Set .Configuration = iConf
        .To = "recipient@gmail.com"

        .CC = "recipient1@gmail.com"

        .BCC = "recipient2@gmail.com"
    
        ' Note: The reply address is not working if you use this Gmail example
        ' It will use your Gmail address automatic. But you can add this line
        ' to change the reply address
    
        .ReplyTo = "me""<me@gmail.com<me@gmail.com>>"
        .FROM = """me""<me@gmail.com><me@gmail.com>"
        .Subject = "report"
        .TextBody = strbody
    
        .AddAttachment file_path & Summary_Report_Name
    
        .AddAttachment file_path & Detailed_Items_Report_Name

        .Send
    
        MsgBox ("Reports have been sent.")
    
    End With

    Set iMsg = Nothing
    Set iConf = Nothing

End Sub    'CDO_Mail()
</me@gmail.com></me@gmail.com>
 
Upvote 0

Forum statistics

Threads
1,214,421
Messages
6,119,392
Members
448,891
Latest member
tpierce

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