Send Email Specific sheets

lizemi

New Member
Joined
Sep 5, 2021
Messages
28
Office Version
  1. 365
Platform
  1. Windows
Good Day

MY current VBA


VBA Code:
Sub send_email()
 
  Dim wPath As String, wFile As String
Dim FName           As String
Dim FPath           As String

Dim wbkExport As Workbook
Dim shtToExport As Worksheet
FPath = "[URL]https://xxxxxxxxxxxxxxx/[/URL]"
FName = Range("d1").Value
[COLOR=rgb(97, 189, 109)]Dim s As Long
For s = 1 To 13
    Sheets(s).Activate[/COLOR]
 [COLOR=rgb(97, 189, 109)]Next s[/COLOR]
(i added this in green and dont think its working)

Set shtToExport = ActiveSheet
Set wbkExport = Application.Workbooks.Add
shtToExport.Copy Before:=wbkExport.Worksheets(wbkExport.Worksheets.Count)
Application.DisplayAlerts = False

wbkExport.SaveAs Filename:=FPath & "\" & FName & ".xlsx"
Application.DisplayAlerts = True
wbkExport.Close SaveChanges:=False




Set dam = CreateObject("Outlook.Application").CreateItem(0)
'
dam.To = "lXXXXXXXX"
dam.Subject = Range("d1")
dam.Body = "Hi Please Find Attached Weekly Dashboard"
dam.Attachments.Add FPath & FName & ".xlsx"
dam.send
MsgBox "Email sent"

End Sub



I have the following VBA that saves a copy of the active sheet and emails it to a specific email address.
I have tried to add to the vba to tell it what sheets I want it to the active sheet to be or change the active sheet to the specific sheet i need emailed.
I will need 5 macros 1 for each manager as each one of them has to get different sheets as in picture
So Jaques needs to get an workbook emailed to him consisting of sheet 1-13 etc etc
1715773441905.png
 
Last edited by a moderator:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Just at a quick glance, you define FPath with a "/" at the end and then when you try to save the file, you add a "\" so your path would look something like:
"https://xxxxxxxxxxxxxxx/\" & FName & ".xlsx"

Try taking out the slash in:
wbkExport.SaveAs Filename:=FPath & "\" & FName & ".xlsx"
 
Upvote 0

Forum statistics

Threads
1,217,346
Messages
6,136,039
Members
449,980
Latest member
asepsujaa

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