I got snips of code from googling to email a worksheet only from a workbook and i made it work by saving the worksheet into a new temp workbook. After i email the worksheet workbook, i close this newly made workbook and end up with a blank excel workbook that is active. then i activate the original workbook with macros. how to get rid of the blank instance of Excel only and keep the other one active?
Sub EmailOneSheet()
Dim oApp As Object
Dim oMail As Object
Dim wb As Workbook
Const fname = "C:\Temp2.xls"
'Turn off screen updating
Application.ScreenUpdating = False
'Make a copy of the active sheet and save it to a temporary file
ActiveSheet.Copy
Cells.Copy
Cells.PasteSpecial xlPasteValues
Set wb = ActiveWorkbook
Application.DisplayAlerts = False
wb.SaveAs "C:Temp2.xls"
Application.DisplayAlerts = True
'Create and show the outlook mail item
Set oMail = CreateObject("Outlook.Application").CreateItem(0)
With oMail 'Add a recipient
.To = "EMAIL ADDRESS"
.Subject = "Emailing active sheet of active workbook"
.Attachments.Add wb.FullName
.Send
End With
wb.Close True ' close the new workbook file that I need to email
'Excel.Parent.Quit ' THese two lines closes all instances of excel
'Application.Quit
Application.ScreenUpdating = True
Set oMail = Nothing
Workbooks("emailfromoutlook.xlsm").Activate ' activate the original opened workbook
End Sub
Sub EmailOneSheet()
Dim oApp As Object
Dim oMail As Object
Dim wb As Workbook
Const fname = "C:\Temp2.xls"
'Turn off screen updating
Application.ScreenUpdating = False
'Make a copy of the active sheet and save it to a temporary file
ActiveSheet.Copy
Cells.Copy
Cells.PasteSpecial xlPasteValues
Set wb = ActiveWorkbook
Application.DisplayAlerts = False
wb.SaveAs "C:Temp2.xls"
Application.DisplayAlerts = True
'Create and show the outlook mail item
Set oMail = CreateObject("Outlook.Application").CreateItem(0)
With oMail 'Add a recipient
.To = "EMAIL ADDRESS"
.Subject = "Emailing active sheet of active workbook"
.Attachments.Add wb.FullName
.Send
End With
wb.Close True ' close the new workbook file that I need to email
'Excel.Parent.Quit ' THese two lines closes all instances of excel
'Application.Quit
Application.ScreenUpdating = True
Set oMail = Nothing
Workbooks("emailfromoutlook.xlsm").Activate ' activate the original opened workbook
End Sub