Send bulk email from Excel issues: 1-Attach multiple files with file paths, 2-Copy visible ranges and 3-Add default email signature keeping formats

randaubienghoc

New Member
Joined
Apr 25, 2020
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone,

As a new VBA learner, I am seeking for your help to solve these three problems when automatically send Outlook email from Excel. The code is now lacking these improvements. Your support would be highly appreciated.

1. Attach multiple files with file paths by criteria (For same customer codes/ subject, send the same email and attach respective files followed their paths in column, skipping the rows with status "Y")

2. Copy and paste to email visible data ranges from Excel keeping formats by criteria (only copy VISIBLE table from column I to O keeping the same format, skipping the rows with status "Y")

3. Add default Outlook email signature at the end of email body keeping formats (insert signature without changing formats).

Please see my macro file and test files to be sent to email & expected first email illustration.

Thank you very much.

pic.png
pic 1.png


VBA Code:
Option Explicit

Sub Send_Mails()
Dim sh As Worksheet
Set sh = ThisWorkbook.ActiveSheet

Dim i As Integer

Dim OA As Object
Dim msg As Object

Set OA = CreateObject("outlook.application")

Dim last_row As Integer
last_row = Application.CountA(sh.Range("A:A"))

For i = 2 To last_row
Set msg = OA.createitem(0)
msg.To = sh.Range("A" & i).Value
msg.cc = sh.Range("B" & i).Value
msg.Subject = sh.Range("C" & i).Value
msg.body = sh.Range("D" & i).Value

If sh.Range("E" & i).Value <> "" Then
    msg.attachments.Add sh.Range("E" & i).Value
End If


msg.display

sh.Range("F" & i).Value = "Sent"

Next i

MsgBox "All the mails have been sent successfully"


End Sub
 

Attachments

  • pic.png
    pic.png
    14.5 KB · Views: 14

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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