I have this code which opens outlook and displays an email. However, I was wondering how to then switch back to excel from outlook.
Thanks
Code:
Sub EmailandSaveCellValue(ByVal strRec As String)
'Variable declaration
Dim oApp As Object, oMail As Object, WB As Workbook, _
FileName As String, MailSub As String, MailTxt As String
'************************************************* ********
'Set email details; Comment out if not required
MailTo = strRec
MailSub = "Please review the attached Diary Event Dates Report."
MailTxt = "This is a Automated Email sent by the user " & Application.UserName
'************************************************* ********
'Turns off screen updating
'Application.ScreenUpdating = False
'Makes a copy of the active sheet and save it to
'a temporary file
ActiveSheet.Copy
Set WB = ActiveWorkbook
FileName = ActiveSheet.Name & ".xls"
On Error Resume Next
Kill "C:\" & FileName
On Error Goto 0
WB.SaveAs FileName:="C:\" & FileName
'Creates and shows the outlook mail item
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
With oMail
.To = MailTo
.CC = MailCC
.BCC = MailBCC
.Subject = MailSub
.Body = MailTxt
.Attachments.Add WB.FullName
.Display
End With
'oMail.Send
'Deletes the temporary file
WB.ChangeFileAccess Mode:=xlReadOnly
Kill WB.FullName
WB.Close SaveChanges:=False
'Restores screen updating and release Outlook
'Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub
Thanks