I have a workbook and 61 of the worksheets represent Employee's, on every worksheet cell C8 shows the department to which that Employee is a part off, C8 on some some of the worksheets will be blank and will not need to be emailed.
What I am trying to do is to be able to select a department via a data validated cell and then click a button which will identify the department from the selection and then only email those sheets where the department matches in C8.
I have some excellent mail examples from Ron de Bruin and the MSKB (which I think are Ron's anyway) but I cannot seem to adapt them to my use.
Can anybody suggest a change to the code below which would look at a cell, let us say B31 (although that may change later) on a work sheet named Reports and then match the value with cell C8 in worksheets emp1:emp61 and then temporarily combine those sheets for emailing.
Code: Select all
Sub EmailWithOutlooka()
Dim oApp As Object, _
oMail As Object, _
WB As Workbook, _
FileName As String
Application.ScreenUpdating = False
ActiveSheet.Copy
Set WB = ActiveWorkbook
FileName = "Departmental Yearly Summary.xls"
On Error Resume Next
Kill "C:\" & FileName
On Error GoTo 0
WB.SaveAs FileName:="C:\" & FileName
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
.Subject = "Departmental Annual Summary!"
.Attachments.Add WB.FullName
.Display
End With
WB.ChangeFileAccess Mode:=xlReadOnly
Kill WB.FullName
WB.Close SaveChanges:=False
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub