Send Email & select attachment from insert file list

mnmhenry

Board Regular
Joined
Mar 28, 2002
Messages
169
Hi Peeps,

I'm stuck again and need the brains-trust!

I am sending an email from Excel. At the moment I am pasting a file address and name into a cell and completing the email. I would like VBA to be able to call the "Insert File" pop up box so I can use the directory to select the file to attach. Is this possible?

O4 & O5 are the cells holding the attachments.

My Code so far -

Sub Sent_Test_Email()
On Error GoTo ErrHandler

' SET Outlook APPLICATION OBJECT.
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")

' CREATE EMAIL OBJECT.
Dim objEmail As Object
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail

.to = ActiveCell.Offset(, 6).Value
.CC = ActiveCell.Offset(, 7).Value
.Subject = ActiveCell.Offset(, 8).Value
.Body = ActiveCell.Offset(, 9).Value
.Attachments.Add Range("O4").Value
.Attachments.Add Range("O5").Value
'.HTMLBody = strbody & "<br>" & Signature
'.HTMLBody = "<HTML><BODY><span style=""color:#80BFFF"">Font Color</span style=""color:#80BFFF""> <br>the <b>bold text</b> here.</br> <br><u>New line with underline</u></br><br><p style='font-family:calibri;font-size:25'>Font size</br></p></BODY></HTML>"
.Display ' Display the message in Outlook.
End With

' CLEAR.
Set objEmail = Nothing: Set objOutlook = Nothing

ErrHandler:
'

ActiveCell.Offset(, 1).Select
ActiveCell.FormulaR1C1 = "=TODAY()"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
'ActiveCell.Offset(0, 1).Select
' Down - Across

End Sub

Thanks for any help.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Add this immediately after the Sub line:
VBA Code:
    Dim attachmentFullName As String
    With Application.FileDialog(msoFileDialogFilePicker)
        .Title = "Select file to attach to email"
        .AllowMultiSelect = False
        If Not .Show Then Exit Sub
        attachmentFullName = .SelectedItems(1)
    End With
and replace one of the .Attachments.Add with:
VBA Code:
    .Attachments.Add attachmentFullName
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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