+ Reply to Thread
Results 1 to 3 of 3

how to add cc in my macro when sending emails.

  1. #1
    Registered User
    Join Date
    11-28-2022
    Location
    england
    MS-Off Ver
    365
    Posts
    28

    how to add cc in my macro when sending emails.

    I was given a macro that allows me to send emails with attachments to suppliers with only the information that relates to them, but I cannot cc recipients. I attempted to change it so I could CC, but I'm not sure how to change the macro. Any assistance would be greatly appreciated.

    In sheet2, column c, beginning on row 2, is where I will add the email addresses to cc.

    here is my macro

    PHP Code: 
    Sub test20221130B()

    Dim rng As RangeAs RangeAddrRange As Range
    Dim i 
    As LonglastRow As LonglastRow2 As Long
    Dim targetWorkbook 
    As Workbook
    Dim objFSO 
    As Object
    Dim varTempFolder 
    As VariantAs Variant
    Dim AttFile 
    As StringDest As String
    Dim sh 
    As WorksheetshMail As Worksheet

    Set sh 
    Sheets("order book")
    Set shMail Sheets("Sheet2")

    lastRow sh.Cells.Find("*"SearchOrder:=xlByRowsSearchDirection:=xlPrevious).Row
    lastRow2 
    shMail.Cells.Find("*"SearchOrder:=xlByRowsSearchDirection:=xlPrevious).Row
    Set AddrRange 
    shMail.Range("A1:B" lastRow2)

    sh.Range("A2:v" lastRow).Value

    Set objFSO 
    CreateObject("Scripting.FileSystemObject")
    varTempFolder objFSO.GetSpecialFolder(2).Path "\Temp " Format(Now"dd-mm-yyyy- hh-mm-ss")
    objFSO.CreateFolder (varTempFolder)

    Application.ScreenUpdating False

    With CreateObject
    ("scripting.dictionary")

    For 
    2 To UBound(v)
    If 
    Not .exists(v(i2)) Then
    .Add v(i2), Nothing

    With sh
    sh
    .Range("A1").AutoFilter 2v(i2)
    Set rng = .AutoFilter.Range
    Set targetWorkbook 
    Workbooks.Add
    .UsedRange.SpecialCells(xlCellTypeVisible).Copy
                    
                     With targetWorkbook
    .Worksheets(Sheets.Count)
                        .
    Range("A1").PasteSpecial xlPasteColumnWidths
                        
    .Range("A1").PasteSpecial xlPasteFormatsOperation:=xlNoneSkipBlanks:=FalseTranspose:=False
                        
    .Range("A1").PasteSpecial xlPasteValuesAndNumberFormatsOperation:=xlNoneSkipBlanks:=FalseTranspose:=False
                    End With
                    
    AttFile 
    v(i2) & ".xlsx"
    Dest Application.WorksheetFunction.VLookup(v(i2), AddrRange2False)

    With targetWorkbook
    '.ActiveSheet.Columns.AutoFit
    .SaveAs varTempFolder & "" & AttFile
    .Close
    End With

    With CreateObject("Outlook.Application").CreateItem(0)
    .To = Dest
    .Subject = "Subject"
    .Body = "Please find the attached order book. please fill in the column that applies to you"
    .Attachments.Add varTempFolder & "" & AttFile
    .display '
    to show
    '.Send 'to send
    End With

    End With
    End 
    If

    Next i
    End With

    Range
    ("A1").AutoFilter
    Application
    .ScreenUpdating True

    objFSO
    .deletefolder (varTempFolder)
    End Sub 


    order book sample.xlsx
    Last edited by excel_rooki; 03-03-2023 at 04:28 AM.

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

    Re: how to add cc in my macro when sending emails.

    Maybe if you change AddRange to just column A and use a Match rather than a Vlookup to get the row of the matching supplier. Then you can retrieve the To and CC from columns B and C respectively.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    11-28-2022
    Location
    england
    MS-Off Ver
    365
    Posts
    28

    Re: how to add cc in my macro when sending emails.

    thank you for the help ByteMarks

+ 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. Advanced Macro, sending emails in outlook
    By benjamin_1986 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2015, 05:55 AM
  2. Macro not Auto-Sending Emails
    By remadison3 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2014, 08:32 PM
  3. Sending Emails via Macro
    By jnoble3 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2013, 03:34 PM
  4. Sending emails through macro
    By nbhatia4u in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-12-2013, 08:01 AM
  5. [SOLVED] HELP! Macro not sending emails
    By g1987 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-23-2012, 12:25 PM
  6. excel macro for sending emails
    By aravindhan_31 in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 12-11-2009, 08:50 AM
  7. Sending macro emails using excel: Send emails with their passwords.
    By loveisblind in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2009, 03:16 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