arnabmit
New Member
- Joined
- Mar 28, 2009
- Messages
- 27
- Office Version
- 365
- 2019
- 2016
- Platform
- 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.
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