Can i send a mail with attachment from excel

Yes, you can send an email with an attachment from Excel using VBA (Visual Basic for Applications). Here's a step-by-step guide:

Prerequisites:

  1. You need to have Excel 2007 or later version.
  2. You need to have Outlook installed on your computer.

Steps:

  1. Open your Excel workbook and go to the Visual Basic Editor by pressing Alt + F11 or by navigating to Developer tab > Visual Basic button.

  2. In the Visual Basic Editor, click Insert > Module to insert a new module.

  3. Paste the following code into the module:

    Sub SendEmailWithAttachment()
     Dim olApp As Object
     Dim olMail As Object
     Dim filePath As String
    
     ' Set the file path and name of the attachment
     filePath = "C:\Path\To\Your\File.xlsx"
    
     ' Create a new Outlook application object
     Set olApp = CreateObject("Outlook.Application")
    
     ' Create a new email object
     Set olMail = olApp.CreateItem(0)
    
     ' Set the email properties
     With olMail
        .To = "[email protected]"
        .Subject = "Email with attachment"
        .Body = "This is the email body"
    
         ' Add the attachment
        .Attachments.Add filePath
    
         ' Send the email
        .Send
     End With
    
     ' Clean up
     Set olMail = Nothing
     Set olApp = Nothing
    End Sub
  4. Replace "C:\Path\To\Your\File.xlsx" with the actual file path and name of the attachment you want to send.

  5. Replace "[email protected]" with the actual email address of the recipient.

  6. Replace "This is the email body" with the actual email body you want to send.

  7. Save the module by clicking File > Save (or press Ctrl + S).

  8. To run the macro, go back to your Excel workbook and press Alt + F8 to open the Macro dialog box. Select the SendEmailWithAttachment macro and click Run.

Tips: