Sub CopyAsht2NwWbk()
'This macro developed for EW timesheet
'01Timesheet Master.xls
'Copies active sheet into new workbook,
'deletes the empty sheets &
'renames the new workbook &
'emails the new workbook
'Hwb is source/active wbk and Nwb is new wbk
Dim Hwb, Nwb As Workbook
'Hws is source/active ws and Nws is new ws
Dim Hws, Nws As Worksheet
'Gives filename and keeps new file in current directory
Dim Sn, Nm, Dt, FN, myPath, msg As String
Dim OutApp As Object
Dim OutMail As Object
Set Hwb = ActiveWorkbook
Set Hws = ActiveSheet
'Application.ScreenUpdating = False
' Set variable to path of active workbook
myPath = ActiveWorkbook.Path
Set Nwb = Workbooks.Add
Hws.Copy Before:=Sheets(1)
'Staff name
Sn = Range("D7").Value
'Adds " WE "
Nm = Sn & " WE "
'Date format for filename
Dt = Format(Range("C25").Value, "DDMMYYYY")
'Workbook name
FN = "Timesheet " & Nm & Dt
Application.DisplayAlerts = False
'Deletes excess sheets
For Each Nws In Sheets
If Left(Nws.Name, 2) = "Sh" Then Nws.Delete
Next Nws
Application.DisplayAlerts = True
ActiveWorkbook.SaveAs (myPath & "/" & FN)
'Opens OL & sets OL visible
'Set OutApp = New Outlook.Application
'OutApp.Application.Visible = True
'Set OutMail = OutApp.CreateItem(olMailItem)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
msg = "Hi Des." & vbCrLf
msg = msg & vbCrLf
msg = msg & "Please find my timesheet attached, thanks." & vbCrLf
msg = msg & vbCrLf
msg = msg & Sn
'On Error Resume Next
With OutMail
.To = "email@2u.com"
.CC = ""
.BCC = ""
.Subject = "TimeSheet " & Sn 'Staff Name in subject
.Body = msg
.Attachments.Add (myPath & "/" & FN & ".xls")
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display 'or use .Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Nwb.Close
Hwb.Activate
Kill (myPath & "/" & FN & ".xls")
End Sub