I am using this code below to generate a copy of my spreadsheet and email it to someone. When I run this code, it will display 4 email windows (all the exact same), how to I correct this? I have also tried to use the .Send instead of .Display but outlook pops up and says "A program is trying to send an e-mail on your befalf.......ect" and when I click allow, excel thinks it didn't work and keeps trying to send over and over and over until I deny and end the macro.
Sub Email_WB()
Set OLF = CreateObject("Outlook.Application")
Application.DisplayAlerts = False
For i = 1 To Worksheets.Count
Set WS = Worksheets("RR Tracker")
WS.Copy
Set wb = ActiveWorkbook
TempFile = "C:\temp\" & WS.Name & ".xlsx"
wb.SaveAs TempFile
wb.Close
Set wb = Nothing
Set objOutlookMsg = OLF.CreateItem(0)
With objOutlookMsg
.To = "test@test.com"
.CC = "test@test.com"
.Subject = "Weekly Report"
.Importance = 2
.Attachments.Add (TempFile)
.Display
End With
Set objOutlookMsg = Nothing
Next
Set OLF = Nothing
MsgBox "All Done!!"
Application.DisplayAlerts = True
End Sub
Thanks,
Chris
Bookmarks