Sub SendEmail()
Dim wb As Workbook
Dim ws As Worksheet
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 = "thevarajan_subramanin@astro.com.my"
fName = "Weekly Summary Report"
Application.DisplayAlerts = False
'Copy to New Sheet '
Sheets(fName).Copy
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("Weekly Summary Report").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
.Send
End With
'Clear Resources
Set MItem = Nothing
Set OutlookApp = Nothing
'Delete File
Kill Pathname:="C:\" & fName & ".xls"
Application.DisplayAlerts = True
End Sub
|