Results 1 to 3 of 3

Macro to email an attachment sending two copies

Threaded View

  1. #1
    Registered User
    Join Date
    07-04-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    54

    Macro to email an attachment sending two copies

    Hi, I've borrowed the following code from http://msdn.microsoft.com/en-us/libr...ffice.11).aspx, which is apparently meant to send an email to the specified address.
    When I run it, however, it instead sends two copies, or, if I choose .Display instead of .Send, opens up two copies of the email with the attachment.

    I'm sure the fix is really simple, but was wondering if anyone could shed any light on my problem?

    Thanks in advance!

    Sub Mail_Workbook_1()
    ' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010.
    ' This example sends the last saved version of the Activeworkbook object .
        Dim OutApp As Object
        Dim OutMail As Object
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
    
        On Error Resume Next
       ' Change the mail address and subject in the macro before you run it.
        With OutMail
            .To = "windy115109@gmail.com"
            .CC = ""
            .BCC = ""
            .Subject = "Processed Trades"
            .Body = "Hello World!"
            .Attachments.Add ActiveWorkbook.FullName
            ' You can add other files by uncommenting the following line.
            '.Attachments.Add ("C:\test.txt")
            ' In place of the following statement, you can use ".Display" to
            ' display the mail.
            .Send   
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    I'm calling this macro within another, which when commenting out this line, runs with no hitches. When I run the code on its own (without calling it from the other macro), it only sends the one copy. However, as soon as I run it within the other macro, I go back to getting two? I have no idea what's going on!

    To call this code, I'm simply using
    Application.Run("Mail_Workbook_1()")
    Last edited by Authentik8; 07-05-2012 at 07:33 AM.

Thread Information

Users Browsing this Thread

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

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