Hi All,
I am trying to configure a button on an excel sheet to send the populated sheet to 2 different recipients. The recipient the email goes to will be dependant on whether a checkbox/ multiple checkboxes in a range are ticked.
At present the sheet I have set up has 2 buttons and requires the user to determine which to press for the email with attached sheet to be sent.
However my boss wants this consolidated into one button which covers all actions. I am sure this is possible, but at the moment it seems to be beyond my abilities.
Simply put:
If checkboxes 1:10 , 22:26 are checked
attach file and send email to recipient
else
if checkboxes 11:21 are checked
attach file and send email to recipient
Current code:
'Email the worksheet to specified recipients LA'
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim strto As String
On Error Resume Next
For Each cell In ThisWorkbook.Sheets("SAP Access Request Form") _
.Range("D66:D67").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" Then
strto = strto & cell.Value & ";"
End If
Next cell
On Error GoTo 0
If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)
'Validation to choose which email route, validate checkboxes in range
If Sheets("Sheet1").CheckBoxes("Check Box 1:Check Box10").Value = xlOn Then
'Launches outlook to send following email LA
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "email@email.co.uk"
.CC = strto
.BCC = ""
.Subject = "Approval Required for SAP access"
.Body = "Hi" & vbLf & vbLf & _
"Please find attached a SAP user request form for your authorisation."
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End If
End If
MsgBox "Thank you, your form has been sent to ."
If Sheets("Sheet1").CheckBoxes("Check Box 11:Check Box21").Value = xlOn Then
MsgBox "testing"
Bookmarks