browse for attachments when sending an email

quintin

Board Regular
Joined
Jun 26, 2013
Messages
52
Good day,

I am trying to browse for the attachment when sending an email to a client - I have the email code working okay, I have come up with this...and it's not working, like I would like it to.

many thanks

Code:
Private Sub CommandButton1_Click()
    Dim OutApp As Object
    Dim OutMail As Object
Dim qfile As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .To = "test@gmail.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hello World!"
        .attachments.Add = qfile

             filepath = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")
If filepath <> False Then
qfile = filepath

End If
        .display
        '.Send
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi, I think you are quite close.

Try this instead:
Code:
Private Sub CommandButton1_Click()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim filepath As Variant

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    'On Error Resume Next
    With OutMail
        .To = "test@gmail.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .Body = "Hello World!"
        filepath = Application.GetOpenFilename("PDF Files (*.pdf), *.pdf")
        If Not filepath = False Then .attachments.Add filepath
        .display
        '.Send
    End With

    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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