Hi All - I'm looking for some help (obviously).
Every Fall we send out Excel calendars to our seasonal staff. They select their committment days and return the Workbook. This year, I am trying somenting different. I will start by saying I haven't coded anyting since 7th grade and I'm 54 now.
I was able to code a command button to email the specific sheet within a workbook to me and a few key people. That seems to be working. However, what I would like to do in addition, is email specific people based on the specific work area:
[Each workbook has this in the first 5 rows]
[Sheets of the workbook]
Each area (Privates & Adults/Mountain Camp/Snow Camp) has a different manager and they each have two (2) Supervisors. I would like to be able to have each Core Area Manager and their Supervisors get emailed (and I would want to be copied) once the seasonal staff has hit "Submit". Below is the code VBA code I am using for the Command Button. Is there a way to have the "Submit" button email based on the work area? The sheets will be protected so the fomulas I have within are protected from change.
Bonus would be if the person submitting the information would also get a copy. I can add an email field below the phone number if needed. Double Bonus is if I can get the email subject to have the last name of the person submitting the calendar.
TIA
Shannon
Private Sub CommandButton1_Click()
Dim xOutlookObj As Object
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set Wb = Application.ActiveWorkbook
ActiveSheet.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
xFile = ".xls
x"
xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
If Wb2.HasVBProject Then
xFile = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
Else
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
End If
Case Excel8:
xFile = ".xls"
xFormat = Excel8
Case xlExcel12:
xFile = ".xlsb"
xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & "\"
Filename = Wb.Name & Format(Now, "dd-mmm-yy")
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Wb2.SaveAs FilePath & Filename & xFile, FileFormat:=xFormat
With OutlookMail
.To = "(ME)@vail.com"
.CC = "(Snow Camp Manager)@vail.com;(Mountain Camp Manager)@vail.com;(Privates & Adults Manager)@vail.com"
.BCC = ""
.Subject = "SRS 2023-24 Schedule"
.Body = "Please keep a copy for yourself or CC yourself on this email." & vbNewLine & vbNewLine & _
"" & vbNewLine & vbNewLine & _
"You can reach out to your Core Area manager after October 1st:" & vbNewLine & _
"Snow Camp - " & vbNewLine & _
"Mountain Camp - " & vbNewLine & _
"Privates & Adults - " & vbNewLine & _
"" & vbNewLine & vbNewLine & _
"Thank you for submitting your schedule."
On Error Resume Next
.Attachments.Add Wb2.FullName
.Display 'or use .Send
End With
Wb2.Close
Kill FilePath & Filename & xFile
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Application.ScreenUpdating = True
End Sub
Every Fall we send out Excel calendars to our seasonal staff. They select their committment days and return the Workbook. This year, I am trying somenting different. I will start by saying I haven't coded anyting since 7th grade and I'm 54 now.
I was able to code a command button to email the specific sheet within a workbook to me and a few key people. That seems to be working. However, what I would like to do in addition, is email specific people based on the specific work area:
[Each workbook has this in the first 5 rows]
[Sheets of the workbook]
Each area (Privates & Adults/Mountain Camp/Snow Camp) has a different manager and they each have two (2) Supervisors. I would like to be able to have each Core Area Manager and their Supervisors get emailed (and I would want to be copied) once the seasonal staff has hit "Submit". Below is the code VBA code I am using for the Command Button. Is there a way to have the "Submit" button email based on the work area? The sheets will be protected so the fomulas I have within are protected from change.
Bonus would be if the person submitting the information would also get a copy. I can add an email field below the phone number if needed. Double Bonus is if I can get the email subject to have the last name of the person submitting the calendar.
TIA
Shannon
Private Sub CommandButton1_Click()
Dim xOutlookObj As Object
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set Wb = Application.ActiveWorkbook
ActiveSheet.Copy
Set Wb2 = Application.ActiveWorkbook
Select Case Wb.FileFormat
Case xlOpenXMLWorkbook:
xFile = ".xls
x"
xFormat = xlOpenXMLWorkbook
Case xlOpenXMLWorkbookMacroEnabled:
If Wb2.HasVBProject Then
xFile = ".xlsm"
xFormat = xlOpenXMLWorkbookMacroEnabled
Else
xFile = ".xlsx"
xFormat = xlOpenXMLWorkbook
End If
Case Excel8:
xFile = ".xls"
xFormat = Excel8
Case xlExcel12:
xFile = ".xlsb"
xFormat = xlExcel12
End Select
FilePath = Environ$("temp") & "\"
Filename = Wb.Name & Format(Now, "dd-mmm-yy")
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Wb2.SaveAs FilePath & Filename & xFile, FileFormat:=xFormat
With OutlookMail
.To = "(ME)@vail.com"
.CC = "(Snow Camp Manager)@vail.com;(Mountain Camp Manager)@vail.com;(Privates & Adults Manager)@vail.com"
.BCC = ""
.Subject = "SRS 2023-24 Schedule"
.Body = "Please keep a copy for yourself or CC yourself on this email." & vbNewLine & vbNewLine & _
"" & vbNewLine & vbNewLine & _
"You can reach out to your Core Area manager after October 1st:" & vbNewLine & _
"Snow Camp - " & vbNewLine & _
"Mountain Camp - " & vbNewLine & _
"Privates & Adults - " & vbNewLine & _
"" & vbNewLine & vbNewLine & _
"Thank you for submitting your schedule."
On Error Resume Next
.Attachments.Add Wb2.FullName
.Display 'or use .Send
End With
Wb2.Close
Kill FilePath & Filename & xFile
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Application.ScreenUpdating = True
End Sub