Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
445
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,

I currently have this setup:

1645629626007.png


My VBA code is this ( credits to @RoryA :) )

VBA Code:
Option Explicit

Private Const FilePath As String = "\\UBSPROD.MSAD.UBS.NET\userdata\t684895\home\Documents\faq folder\"
Sub send_email_complete()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim i As Long
    Dim ws As Worksheet
    Dim col As New Collection, itm As Variant
    Dim ToAddress As String, CCAddress As String, EmailSubject As String
   
    '~~> Change this to the relevant worksheet
    '~~> that has the emails (right now Search Export has it)
    Set ws = ThisWorkbook.Sheets("Search Export")

    Set OutApp = CreateObject("Outlook.Application")
    
    Dim BodyText As String
    BodyText = ws.Range("P2") & "<BR>" & "<BR>" & _
         "<b><u>" & ws.Range("P3") & "</b></u>" & " " & _
         ws.Range("P4") & "<BR>" & "<BR>" & _
         ws.Range("P5") & "<BR>" & _
         ws.Range("P6")
         
   Dim AttachmentName As String
   AttachmentName = FilePath & ws.Cells(2, 15).Value2
         
    For i = 2 To ws.Cells(ws.Rows.Count, "J").End(xlUp).Row
      '~~> Constructing addresses and subject
      
      ToAddress = ws.Cells(i, 11).Value2 & ";" & ws.Cells(i, 12).Value2 & ";" & ws.Cells(i, 13).Value2
                  
      CCAddress = ws.Cells(i, 14).Value2
                   
      EmailSubject = ws.Cells(i, 10).Value2
      '~~> This creates a new email (so we can send out multiple emails)
      Set OutMail = OutApp.CreateItem(0)

      With OutMail
         .To = ToAddress
         .CC = CCAddress
         .Subject = EmailSubject
         .HTMLBody = BodyText
         .Attachments.Add AttachmentName
         
         .Display
      
      End With
   Next i

End Sub

Now my question is whether it is possible to somehow change my VBAcode so instead of targeting multiple columns cells, like it does now with row K-M & N as CC, if it could target just a single column, for example column K only and then email to multiple emails?

I imagine that I would write something along the line of "test1@mail.com, test2@mail.com, test3@mail.com" in cell K2 and then the vba macro would separate these emails based on the comma "," and send out an email to each separate email.

Is this possible? If so I would truly appreciate some assistance here!

Thank you very much for reading this everybody! :)

Best regards,
Jyggalag
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Yes, it is possible, using exactly the method you describe. ;)
 
Upvote 0
Use semicolons (like in the code) in the cell, not commas.
 
Upvote 0
Solution
Use semicolons (like in the code) in the cell, not commas.
Wow.

That was surprisingly easy! It worked!

Thank you so much Rory! Truly appreciated :)

Kind regards,
Jyggalag
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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