Attaching a file to an automated email

philfloyduk

Board Regular
Joined
Jan 6, 2011
Messages
82
Hi.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
I use a spreadsheet with Visual Basic that automatically produces a PDF invoice and also sends a confirmation email once a job has been completed on the system. I'd like the email to have the PDF attached to it. I have two textboxes on the form that manages these jobs, one contains the file name, the other contains the location of the file. I'd like to use this information to locate the file that's attached to the email.<o:p></o:p>
<o:p></o:p>
I've tried to modify the following line of text to locate my file but I'm struggling:<o:p></o:p>
<o:p></o:p>
myEmailMessage.Attachments.Add TheFileLocation & TheFileName & FileExtStr<o:p></o:p>
<o:p></o:p>
The textbox names are:<o:p></o:p>
<o:p></o:p>
tbPDFFileExtension, &<o:p></o:p>
tbFileName<o:p></o:p>
<o:p></o:p>
Any help would be gratefully received.<o:p></o:p>
<o:p></o:p>
Thanks in advance,<o:p></o:p>
<o:p></o:p>
Phil<o:p></o:p>
<o:p> </o:p>
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,

You can use this;

Code:
Sub Mailer()

    Dim OutApp As Object, OutMail As Object
                   
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
    
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = ""
        .Body = ""
        .Attachments.Add ActiveWorkbook.FullName 'Change to suit
        .Display
    End With
                    
    Set OutMail = Nothing
    Set OutApp = Nothing
            
End Sub
 
Upvote 0
Hi Mikey, thanks for you response.

How to I ammend the .add line to locate the file from the information in my textboxes?
 
Upvote 0
Hi,

Just put in the filepath instead of ActiveWorkbook.

Code:
.Attachments.Add "C/Desktop/MyFile.pdf"
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,513
Members
452,921
Latest member
BBQKING

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