VBA Email Files

Zibi

Board Regular
Joined
Feb 2, 2012
Messages
73
Hello,
Please help, I need vba to email using outlook 2013 specific files to group of people with subject and Message, all information would be on spreadsheet in the row, the code should stop when last row is empty

column a and b has to: email
column c, d, e and f has CC: emil
column g has file name
column h has file location
column I has message that should be included with the email
column J has subject of the email

Please help

to: to: cc: cc: cc: cc:
email address email address email address email address email address email address File Name File Location Message Subject
John@cast.net Andy@cast.net BOB@cast.net Dan@cast.net jj@cast.net BB@cast.net New C:/EmailFile Email to you Hello
John@cast.net Andy@cast.net BOB@cast.net Dan@cast.net jj@cast.net BB@cast.net Old C:/EmailFile Email to US Call me
BB@cast.net Andy@cast.net File1 C:/EmailFile Email to KR Best
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Looks like when I post the message all was squished,
Hello, Please help, I need vba to email using outlook 2013 specific files to group of people with subject and Message,
all information would be on spreadsheet in the row,
the code should stop when last row is empty
column a and b has to: email column
c, d, e and f has CC: emil
column g has file name
column h has file location
column I has message that should be included with the email
column J has subject of the email
Please help
 
Upvote 0
Did you look at the link in Post #2 ???
 
Upvote 0
Looks like my post was squished
Hello, Please help, I need vba to email using outlook 2013 specific files to group of people with subject and Message,
all information would be on spreadsheet in the row,
the code should stop when last row is empty
column a and b has to: email
column c, d, e and f has CC: emil
column g has file name
column h has file location
column I has message that should be included with the email
column J has subject of the email


Excel 2010
ABCDEFGHIJ
1To:To:CC:CC:CC:CC:File NameFile LocationMessageSubject
2AA@mail.comBB@mail.comCC@mail.comDD@mail.comEE@mail.comDE@mail.comNewC:/MailhelloGood
3CC@mail.comAA@mail.comOldC:/MailHiNot
4DD@mail.comEE@mail.comDE@mail.comOld and NewC:/MailOKYes
Sheet1
 
Upvote 0
??????......Did you look at the link in Post #2 ???
 
Upvote 0
Hi Michal,

Thanks for your help, I just noticed the code you send, how can I change the code to change message and subject for each email line?

Thanks
Zibi
 
Upvote 0
What code ??...I didn't post any code !!!...:confused:
 
Upvote 0
Hi Michal,

The code was on the page that I got by following the link on post #2.

Make a list in Sheets("Sheet1") with :

In column A : Names of the people
In column B : E-mail addresses
In column C:Z : Filenames like this C:\Data\Book2.xls (don't have to be Excel files)

The Macro will loop through each row in "Sheet1" and if there is a E-mail address in column B
and file name(s) in column C:Z it will create a mail with this information and send it.
Sub Send_Files()
'Working in Excel 2000-2016
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
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("Sheet1")

Set OutApp = CreateObject("Outlook.Application")

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

'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1")

If cell.Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)

With OutMail
.to = cell.Value
.Subject = "Testfile"
.Body = "Hi " & cell.Offset(0, -1).Value

For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
If Trim(FileCell) <> "" Then
If Dir(FileCell.Value) <> "" Then
.Attachments.Add FileCell.Value
End If
End If
Next FileCell

.Send 'Or use .Display
End With

Set OutMail = Nothing
End If
Next cell

Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub


thank you for your help
 
Upvote 0
change this
Code:
With OutMail
.to = cell.Value
.Subject = "Testfile"
.Body = "Hi " & cell.Offset(0, -1).Value

TO

Code:
With OutMail
.to = cell.Value
.Subject = cell.Offset(0, 8).Value
.Body = cell.Offset(0, 7).Value
 
Upvote 0

Forum statistics

Threads
1,216,157
Messages
6,129,195
Members
449,493
Latest member
JablesFTW

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