+ Reply to Thread
Results 1 to 3 of 3

How to send each sheet to different mail adress

  1. #1
    Registered User
    Join Date
    03-21-2023
    Location
    Almere, Netherlands
    MS-Off Ver
    Microsoft 365
    Posts
    2

    How to send each sheet to different mail adress

    Hi,

    I have made a code to send each sheet to a mail adress. However I don't succeed in sending the sheets based on a adress list.

    In Sheet "Adressenlijst" I have the name of the other sheets in Column A, the name of the adressee in column B, and in column C the email adresses.

    So I want for sheet "Amsterdam Oost", to lookup the name in Sheet "Adressenlijst" and then pick column C.

    The code works when I just enter an email adress at To, but now it cannot find the email adress. I tried using Vlookup and if .. then

    Can anybody help? Below the code.

    Thanks!



    Sub Adam()

    Dim iConfirmation As VbMsgBoxResult
    iConfirmation = MsgBox("Emails verzenden?", vbYesNo + vbQuestion, "Confirmation")
    If iConfirmation = vbNo Then Exit Sub

    For Each sh In ThisWorkbook.Sheets
    Dim Wb As Workbook
    Dim FileName As String
    Dim OutlookApp As Object
    Dim OutlookMail As Object
    Dim adress As Object

    On Error Resume Next
    Set Wb = Application.ActiveWorkbook
    If sh.Name = "Amsterdam West" Or sh.Name = "Amsterdam Oost" Then
    FileName = sh.FullName
    xIndex = VBA.InStrRev(FileName, ".")
    If xIndex > 1 Then FileName = VBA.Left(FileName, xIndex - 1)
    FileName = sh.Name + ".pdf"
    sh.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FileName

    Set myrange = Sheets("Adressenlijst").Range("A:C")
    Adresses = "Vlookup(sh.Name, myrange, 3, 0)"


    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
    With OutlookMail
    .To = Adresses
    .CC = ""
    .BCC = ""
    .Subject = "Text"
    .Body = "Text"
    .Attachments.Add FileName
    .Send
    End With
    Kill FileName
    Set OutlookMail = Nothing
    Set OutlookApp = Nothing



    End If
    Next sh

    End Sub



    OR


    For Each cell In Sheets("Adressenlijst").Columns("A").Cells.SpecialCells(xlCellTypeConstants)

    If cell.Value = sh.Name Then




    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
    With OutlookMail
    .To = cell.Value.Offset(0, 2).Select
    .CC = ""
    .BCC = ""
    .Subject = "Text"
    .Body = "text"
    .Send
    End With
    Kill FileName
    Set OutlookMail = Nothing
    Set OutlookApp = Nothing

    End If
    Next cell

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: How to send each sheet to different mail adress

    Does this work for you?

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-21-2023
    Location
    Almere, Netherlands
    MS-Off Ver
    Microsoft 365
    Posts
    2

    Re: How to send each sheet to different mail adress

    Yes! Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Printing mail adress label using excel vba
    By najumdn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-14-2015, 06:01 PM
  2. Replies: 1
    Last Post: 03-11-2014, 12:24 PM
  3. [SOLVED] Formula to extract text before the first dot in an E-mail adress
    By Rambo4711 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-02-2013, 05:18 AM
  4. Trying to get an screenshot and mail it to an email adress
    By basmienis in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2012, 05:26 AM
  5. How to e-mail selected row and use e-mail address in a cell to send e-mail from excel
    By syedalamgir in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2010, 02:15 AM
  6. stop e-mail adress becoming hyperlink
    By Nigel_hough in forum Excel General
    Replies: 1
    Last Post: 01-14-2008, 09:01 AM
  7. [SOLVED] How do I send a xl-sheet as a mail using a VBA-script?
    By SOJ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-01-2005, 05:20 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1