Results 1 to 6 of 6

Email Spreadsheet with Outlook Macro

Threaded View

  1. #1
    Registered User
    Join Date
    08-09-2012
    Location
    Owensboro, KY
    MS-Off Ver
    Excel 2010
    Posts
    10

    Email Spreadsheet with Outlook Macro

    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
    Last edited by chriswathen; 10-24-2012 at 10:33 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1