Sending e-mail, multiple attachment, different names VBA

gallzsoltv

New Member
Joined
Feb 7, 2019
Messages
2
Hello!

A have a working macro (sending email), but I want to upgrade it.



Here is the excel sheet "Munka1":

[TABLE="width: 788"]
<colgroup><col><col><col><col></colgroup><tbody>[TR]
[TD].to[/TD]
[TD].cc[/TD]
[TD].body[/TD]
[TD].attachments[/TD]
[/TR]
[TR]
[TD]smith@gmail.com[/TD]
[TD]cc@cc.com; [email]bb@bb.com[/EMAIL][/TD]
[TD]HI ALL[/TD]
[TD]C:\Users\gall\Desktop\Test\Smith Jackson_tomorrow_201812.xlsx[/TD]
[/TR]
[TR]
[TD]joe@gmail.com[/TD]
[TD]cc@cc.com; [email]bb@bb.com[/EMAIL][/TD]
[TD]HI ALL[/TD]
[TD]C:\Users\gall\Desktop\Test\Joe Simon data_sending_201812.xlsx[/TD]
[/TR]
[TR]
[TD]neo@gmail.com[/TD]
[TD]cc@cc.com; [email]bb@bb.com[/EMAIL][/TD]
[TD]HI ALL[/TD]
[TD]C:\Users\gall\Desktop\Test\Neo James_data sending_201812.xlsx[/TD]
[/TR]
[TR]
[TD]neo@gmail.com[/TD]
[TD]cc@cc.com; [email]bb@bb.com[/EMAIL][/TD]
[TD]HI ALL[/TD]
[TD]C:\Users\gall\Desktop\Test\Neo James_analize test_201812.xlsx[/TD]
[/TR]
[TR]
[TD]anna@gmail.com[/TD]
[TD]cc@cc.com; [email]bb@bb.com[/EMAIL][/TD]
[TD]HI ALL[/TD]
[TD]C:\Users\gall\Desktop\Test\Anna Smith_today_201812.xlsx[/TD]
[/TR]
</tbody>[/TABLE]

Here is the macro:
Code:
Sub Sending_Mail()


Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range






With Application
    .EnableEvents = False
    .ScreenUpdating = False
End With


Set sh = Sheets("Munka1")




Set OutApp = CreateObject("Outlook.Application")


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




    Set rng = sh.Cells(cell.Row, 1).Range("D1:Z1")
    
    If cell.Value Like "?*@?*.?*" And _
    Application.WorksheetFunction.CountA(rng) > 0 Then
        Set OutMail = OutApp.CreateItem(0)
        
        With OutMail
            .to = sh.Cells(cell.Row, 1).Value
            .CC = sh.Cells(cell.Row, 2).Value
            .Subject = "HI all!!"         '<<<
           
            
            For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
                If Trim(FileCell.Value) <> "" Then
                    If Dir(FileCell.Value) <> "" Then
                        .Attachments.Add FileCell.Value
                                                                      
                    End If
                End If
                
            .Display
            Next FileCell
                                   
        End With
        
        Set OutMail = Nothing
    End If
Next cell


Set OutApp = Nothing


With Application
    .EnableEvents = True
    .ScreenUpdating = True
End With






End Sub


How it is possible to send multiple attachment by ONE email?
For exemple do not send for Neo two emails with one-one attachment, send just ONE, with two attachment. I think I need DO - while command... Can you help me out?

Thanks for the answers!
 
Last edited by a moderator:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Please update on the same.. what will code for send multiple attachments in one mail with path given in two or more column
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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