Automated email based on check boxes

queysoft

New Member
Joined
Aug 3, 2021
Messages
49
Office Version
  1. 2016
Platform
  1. Windows
Hello. Currently I use the following code to send emails out via a click box on on of my excel sheets. I was wondering if anyone thinks its possible to have check boxes for different departments (there are 6 departments) and only have the email go to the departments I have ticked?

Private Sub CommandButton1_Click()
'Updated by Extendoffice 2017/9/14
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Body content" & vbNewLine & vbNewLine & _
"Hi - An update - please see attached." & vbNewLine & _
"Many thanks."
On Error Resume Next
With xOutMail
.To = "XXXXX@X.com"
.CC = "XXXXX@t.com........etc etc"
.BCC = ""
.Subject = "Data Analysis UPDATE"
.Body = xMailBody
.Attachments.Add ActiveWorkbook.FullName
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I put ActiveX checkboxes in column C and made the following test code that prints the email addresses of the checked rows in the Immediate window. Your code could be modified to add them to the To field instead.

VBA Code:
Sub EmailsToChecked()
    Dim oleObj As OLEObject
    Dim ws As Worksheet

    Set ws = ActiveSheet
    
    For Each oleObj In ws.OLEObjects
        If oleObj.Object.Value Then
            Debug.Print oleObj.TopLeftCell.Offset(0, 2).Value
        End If
    Next
End Sub
checkboxes.png
 
Upvote 0
Solution

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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