I have an excellent script that came from Ron de Bruin. It creates an Outlook email message, pulls text from a range for the body, and attaches files.
Works great when you need to send the same attachments every time. I need to attach files based on a path created on another sheet.
Here's the email code:
I need to use a path created by formulas on this sheet (named SendFloorRequest). The paths will always be in J1 and J2.
Works great when you need to send the same attachments every time. I need to attach files based on a path created on another sheet.
Here's the email code:
VBA Code:
Sub SendPlanRequestEmail()
Dim Ans As VbMsgBoxResult
Ans = MsgBox("Are you sure you want to Send a Floor Plan Request?", vbYesNo + vbQuestion)
If Ans = vbNo Then Exit Sub
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Sheets("SendFloorRequest").Visible = True
Sheets("SendFloorRequest").Select
'ActiveSheet.Unprotect
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set rng = Nothing
On Error Resume Next
Set rng = Selection.SpecialCells(xlCellTypeVisible)
Set rng = Sheets("SendFloorRequest").Range("FloorPlanRequest").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "jp@testemail.com"
.CC = Settings.CCEmailReturn.Value
.BCC = Settings.BCCEmailReturn.Value
.Subject = "Floor Plan Request"
.htmlbody = RangetoHTML(rng)
.Attachments.add ("\\GLC-SERVER\Pulte\AND_Andover_Forest_7220\AND_001\AND_001_plot_plan.pdf")
.Attachments.add ("\\GLC-SERVER\Pulte\AND_Andover_Forest_7220\AND_001\AND_001_plans.pdf")
.display
'.Send
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
I need to use a path created by formulas on this sheet (named SendFloorRequest). The paths will always be in J1 and J2.