anantashesh

New Member
Joined
Dec 15, 2014
Messages
8
Hi,

Have been using the forums for a long time for various excel related tips and help. However I cannot find a solution to my current problem and want your help. :)

I have to mail multiple people, both in "To" and "CC", with each mail containing a separate PPT. Now, I have found macros for mail merge with CC and mail merge with attachments. What I am looking for is a combination of both.

Ideally what I would like the Macro to do is pick multiple "To" from one column, "CC" from another column and give me a pop up window asking me to attach the PPT for each mail.

Any help in this direction will be greatly appreciated.

Thanks!!!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi. Welcome to the board :)

What code do you have so far?
And what email client are you using?

/AJ
 
Upvote 0
Hi Adam,

To be honest, I don't have any working code for what I am looking for. I have tried tweaking the code found at Merging With Attachments. But it is a Word Macro and I am not able to use it properly.

I am very new to macros and my knowledge is very limited in this area.

Please let me know what else I can do for a solution to my problem.
 
Last edited:
Upvote 0
OK. This code appears to compile but alas I can't test it because we use Lotus Notes at work (don't ask) and from that link it looks like you want it for Outlook?

Well give this a go and see if it works for you

Code:
Option Explicit

Public Sub TestMail()

Dim newMail         As Outlook.MailItem
Dim toRange         As Range
Dim ccRange         As Range
Dim fName           As Variant

Set toRange = Sheets("Sheet1").Range("B2:B5")       'Change as required
Set ccRange = Sheets("Sheet1").Range("C2:C5")       'Change as required
With Application.FileDialog(msoFileDialogOpen)

    .AllowMultiSelect = False
    .Filters.Clear
    .Filters.Add "PowerPoint Files", "*.pptx"
    .Filters.Add "PowerPoint 97-2003 Files", "*.ppt"
    .Show
    
    Dim i As Integer
    For i = 1 To .SelectedItems.Count
        fName = .SelectedItems(i)
    Next i
    
End With

If fName <> False Then

    Set newMail = Outlook.CreateItem(olMailItem)
    
    With newMail
    
        Dim cell As Range
    
        For Each cell In toRange
            If cell.Value <> "" Then .To = .To & cell.Value & ";"
        Next cell
        .To = Left(.To, Len(.To) - 1)
        
        For Each cell In ccRange
            If cell.Value <> "" Then .CC = .CC & cell.Value & ";"
        Next cell
        .CC = Left(.CC, Len(.CC) - 1)
    
        .Attachments.Add fName, olByValue
        .Send
        
    End With

End If

End Sub

Hope that helps.

/AJ
 
Upvote 0
It seems to be running fine but towards the end I get an error on ".Send".

Run-Time Error '-2147467259 (80004005)':
Outlook does not recognize one or more names.

Any idea on why this error is popping up and how I can solve it?
 
Upvote 0
Change .Send to .Display and run it again. You should then be able to check all the names are valid.
Code:
        .Attachments.Add fName, olByValue
        .Display

/AJ
 
Upvote 0
Thank You so much for your help and sorry for bugging you, but there is one last error coming up.

The email IDs are not coming out properly in outlook.

I have written the email IDs in this manner:

In outlook, they are appearing as

To: anant@xxxxxx.co.invenkatesh.sp@afafdfdaf.co.i
CC: sameer@xxxxx.co.inanant@xxxxxx.co.i

Attachments and everything is coming out just like I want it.

Please solve this issue also.
 
Upvote 0
Apologies, my code wasn't great. Try replacing the entire With block as so...
Code:
    With newMail
    
        Dim cell            As Range
        Dim myRecipient      As Outlook.Recipient
    
        For Each cell In toRange
            If cell.Value <> "" Then .Recipients.Add (cell.Value)
        Next cell
        
        For Each cell In ccRange
            If cell.Value <> "" Then
                Set myRecipient = newMail.Recipients.Add(cell.Value)
                myRecipient.Type = olCC
            End If
        Next cell
    
        .Attachments.Add fName, olByValue
        .Display
        
    End With

/AJ
 
Upvote 0
Cool thanks for the feedback. Apologies for not acknowledging before, I was actually off over Christmas for a change!

/AJ
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

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