Consulting

Results 1 to 5 of 5

Thread: Solved: Emailing CC. recipients

  1. #1
    VBAX Tutor
    Joined
    Mar 2009
    Posts
    227
    Location

    Solved: Emailing CC. recipients

    Hi guys

    I have a macro thanx to an expert here(xld). It sends emails to multiple recipients, now I need to add a line that will enable it to CC. the email to recipients listed in the first Row (Sheet1 - Row 1).

    Here's the code



    [VBA]
    Sub SendMailNEST()
    Const MatchCode As String = "NEST"
    Dim wb As Workbook
    Dim LastRow As Long
    Dim LastCol As Long
    Dim OLApp As Object
    Dim EmailItem As Object
    Dim EmailRecip As Object
    Dim j As Long



    With Worksheets("Sheet1")
    Worksheets("Sheet2").Copy

    Set wb = ActiveWorkbook
    wb.SaveAs "Part of" & ThisWorkbook.Name & "" & ".xls"
    wb.ChangeFileAccess xlReadOnly

    Set OLApp = CreateObject("Outlook.Application")
    Set EmailItem = OLApp.CreateItem(0)

    EmailItem.Subject = "Recap"
    LastCol = .Cells(2, .Columns.Count).End(xlToLeft).Column
    For j = 2 To LastCol

    Set EmailRecip = EmailItem.Recipients.Add(.Cells(2, j).Value)
    EmailRecip.Type = 1
    Next j
    EmailItem.Body = "Hi, " & .Cells(2, 1).Value & ", here is today's summary"
    EmailItem.Attachments.Add wb.FullName
    EmailItem.Display 'Send

    Kill wb.FullName

    Set wb = Nothing
    Set EmailItem = Nothing
    Set OLApp = Nothing
    End With
    End Sub
    [/VBA]


    Any ideas?

    Thanks

  2. #2
    just include one more line like this in your code. marked in red. it assumes that the cell is A1 in that existing sheet.

    Set EmailRecip = EmailItem.Recipients.Add(.Cells(2, j).Value) 
                EmailRecip.Type = 1 
            Next j 
            EmailIteam.CC=cells(1,1).value
            EmailItem.Body = "Hi, " & .Cells(2, 1).Value & ", here is today's summary" 
            EmailItem.Attachments.Add wb.FullName 
            EmailItem.Display 'Send

  3. #3
    VBAX Tutor
    Joined
    Mar 2009
    Posts
    227
    Location
    Hey thaks nirvana,

    I tried it but that doesnt work

    I did
    EmailItem.CC = cells(1,j).Value

    as it has to be CC'd to all the addresses in Row 1.

    any suggestions to adjust it?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Set oRecipient = _
    oMailItem.Recipients.Add("someone@somewhere.com")
    oRecipient.Type = 1 '1 = To, use 2 for cc
    'keep repeating these lines with
    'your names, adding to the collection.
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor
    Joined
    Mar 2009
    Posts
    227
    Location
    yup it sure works great XLD!
    you got it again, thanksssssssssssssssss

Posting Permissions

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