Sub SendEmail()
Dim wb As Workbook
Dim ws As Worksheet
Dim strShName As String
Dim fName As String
Dim SendTo As String
Dim OutlookApp As Object
Dim MItem As Object
Dim subject_ As String
Dim attach_ As String
Dim pWord As String
'Create Outlook
Set OutlookApp = CreateObject("Outlook.Application")
pWord = "rbs"
SendTo = "[email protected]"
strShName = "Weekly Summary Report"
Sheets(strShName).Copy
fName = strShName & "@" & ThisWorkbook.Sheets("Detail Task").Range("C2")
Application.DisplayAlerts = False
'Copy to New Sheet '
Set ws = ActiveSheet
With ws
.Unprotect (pWord)
With .Range("A1", .Range("A1").End(xlUp))
.Copy
.PasteSpecial Paste:=xlPasteFormats
.PasteSpecial Paste:=xlPasteValues
End With
.Range("A30").Formula = "=hyperlink(""\\Poaabc04\regional programming\RBS Prime Data\RBS Productivity & KPI Measurement"",""For more details: Click here"")"
.Range("A1").Select
End With
'Save Temp Copy'
Set wb = ActiveWorkbook
With wb
.Sheets(strShName).Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="rbs"
.SaveAs Filename:="C:\" & fName & ".xls"
.Close
End With
'Fill in Subject Details'
subject_ = fName & ".xls"
attach_ = "C:\" & fName & ".xls"
'Create the Email
Set MItem = OutlookApp.createitem(0)
With MItem
.To = SendTo
.Subject = subject_
.attachments.Add (attach_)
'Send the Email
.display
End With
'Clear Resources
Set MItem = Nothing
Set OutlookApp = Nothing
'Delete File
Kill Pathname:="C:\" & fName & ".xls"
Application.DisplayAlerts = True
End Sub
|