Quote:
Originally Posted by Gaura215
I have a worksheet, which has the following:
1) Coloum A have the name of the files of the attachments;
2) Coloum B have the email addresses;
3) Coloum C have the path where the attachement are saved;
I want a macro which can email all the attachements with the name as in Coloum A to there corresponding email address as mentioned in Coloum B. All attachments are saved in the same folder, path is mentioned in Coloum C.
I want these mails to be displayed and not sent directly.
All excel/macro gurus, please help.
|
Thankfully I had created similar code for a previous post recently. This macro goes into Outlook, and requires the Excel file with the attachment names and addresses to be open to work.
Firstly, copy and paste the following code into Outlook. You can do this by selecting Tools/Macro/Visual Basic Editor and pasting in the following code.
In the code, you will notice that I have also added in the commands for you to put in a subject and send the emails, but these are remarked out as your request was just to add the address and attachment and not send the email. You can adjust these as required later.
Code:
Sub ReadExcel()
Dim ExcelObject As Object
Dim OutlookApp As Outlook.Application
Dim NewMessage As Outlook.MailItem
Dim OutlookNamespace As Outlook.NameSpace
Dim fName, fLoc, eAddress As String
Dim fNameAddress, fLocAddress, eAddressAddress As String
' Set up the spreadsheet you want to read
On Error Resume Next
Set ExcelObject = GetObject(, "Excel.Application")
If Not Err.Number = 0 Then
MsgBox "You need to have Excel running with the appropriate spreadsheet open first", vbCritical, "Excel Not Running"
End
End If
' Read in the data and create a new message with attachment for each Excel entry
CellRow = 1
Set OutlookApp = Outlook.Application
Do Until ExcelObject.Range(fNameAddress) = ""
fNameAddress = "A" & CellRow
eAddressAddress = "B" & CellRow
fLocAddress = "C" & CellRow
fName = ExcelObject.Range(fNameAddress)
fLoc = ExcelObject.Range(fLocAddress)
eAddress = ExcelObject.Range(eAddressAddress)
fName = fLoc & "\" & fName
Set OutlookApp = Outlook.Application
Set NewMessage = OutlookApp.CreateItem(olMailItem)
Set myAttachments = NewMessage.Attachments
myAttachments.Add fName
With NewMessage
.Recipients.Add eAddress
.Attachments = fName
.Display
' .Subject = "Put your subject here"
' .Send
End With
CellRow = CellRow + 1
fNameAddress = "A" & CellRow
Loop
End Sub