Excel VBA : Save and Email an Excel worksheet

arnabmit

New Member
Joined
Mar 28, 2009
Messages
27
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
VBA Noob here.

I want to:

A. Save worksheet with filename in the variable shtName in the path %userprofile%\Documents\Batch Reports\

B. Send that file as an email

Seeking guidance to get this done. This is what I have managed to come up with till now, then I got completely lost.

VBA Code:
Sub SaveBatch()

    Dim eApp As Object
    Dim eMal As Object
    Dim wb As Workbook
    
    Set eApp = CreateObject("Outlook.Application")
    Set eMal = eApp.CreateItem(0)
    
    Set wb = Workbooks.Add
    ActiveWorkbook.Sheets(ShtName).Copy before:=wb.Sheets(1)
    wb.SaveAs Filename:=ShtName, FileFormat:=xlWorkbookDefault
    
    eMal.To = "abc@xyz.com"
    eMal.CC = "xyz@abc.com"
    eMal.Subject = "Batch Report - " & ShtName
    eMal.Attachments.Add Source:=ActiveWorkbook.Sheets(ShtName)
    eMal.Send
    
    Set eApp = Nothing
    Set eMal = Nothing

End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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