Results 1 to 3 of 3

Thread: I need a Macro in Excel by which I can send Email with Attachments

  1. #1
    Join Date
    Jan 2012
    Posts
    23

    I need a Macro in Excel by which I can send Email with Attachments

    I have a worksheet, which has the following:
    1. Column A have the name of the files of the attachments;
    2. Column B have the email addresses;
    3. Column C have the path where the attachment are saved;

    I want a macro which can email all the attachments with the name as in Column A to there corresponding email address as mentioned in Column B. All attachments are saved in the same folder, path is mentioned in Column C. I want these mails to be displayed and not sent directly. All excel/macro gurus, please help.

  2. #2
    Join Date
    Jul 2011
    Posts
    623

    Re: I need a Macro in Excel by which I can send Email with Attachments

    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

  3. #3
    Join Date
    Aug 2011
    Posts
    566

    Re: I need a Macro in Excel by which I can send Email with Attachments

    You can use sendmail. Example below:
    Code:
     Sub EnvoiMail () Workbooks ("xxxxx"). SendMail Recipients: = "xyz@xyz.com", _ Subject: = "Test sending workbook", _ ReturnReceipt: = True End Sub
    This macro sends, via the default browser, a mail recipient whose address is here xyz @xyz.com. The subject is indicated in Subject. You can put ReturnReceipt to True to request a return receipt (optional). Attached, the specified workbook that is sent to Sendmail. It could be the workbook containing the macro (ThisWorkbook), or the active workbook (ActiveWorkbook), etc..

Similar Threads

  1. Excel 2003 Macro doesn't work in Excel 2007
    By jjaw in forum Windows Software
    Replies: 3
    Last Post: 03-01-2014, 03:28 PM
  2. Unable to open Word or Excel attachments recd in email
    By Damien25 in forum MS Office Support
    Replies: 1
    Last Post: 04-02-2013, 01:15 PM
  3. How to Send PDF Attachments in Email on ipad
    By jAYASENA in forum Portable Devices
    Replies: 6
    Last Post: 24-04-2012, 06:30 PM
  4. Replies: 3
    Last Post: 25-01-2012, 12:03 PM
  5. Macro to convert file into PDF and then send via email
    By MAGALY in forum Software Development
    Replies: 5
    Last Post: 09-12-2009, 05:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,310,507.62518 seconds with 17 queries