VBA Code - add emails to outlook BCC from list (that updates)

NormChart55

New Member
Joined
Feb 22, 2022
Messages
44
Office Version
  1. 2016
Platform
  1. Windows
Hello All - I am looking to tweak my macro to pull the .BCC emails from a pivot list that could change month to month (as users are added/removed from a program) and add them into the outlook email that is getting created. The pivot email data starts at Sheet2 cell E5 but the end of the pivot could be variable month to month. Hoping for an easy solution to be able to pull this information into the .BCC section of the email.


VBA Code:
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim StrBody As String
LDate = Date
StrBody = "Text," & "<br>" & "<br>" & _
"Text." & "<br>"
Set rng = Nothing
On Error Resume Next
'Only the visible cells in the selection
'Set rng = Selection.SpecialCells(xlCellTypeVisible)
'You can also use a fixed range if you want
Set rng = Sheets("Ref").Range("AX1:AY1").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
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.CC =
.BCC =
.Subject =
.Display 'or use .Display
.HTMLBody = StrBody & RangetoHTML(rng) & .HTMLBody
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
VBA Code:
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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