+ Reply to Thread
Results 1 to 5 of 5

Button to automate sending two different worksheets as attachments via same email

Hybrid View

jungleskipper1 Button to automate sending... 04-12-2015, 06:31 PM
john55 Re: Button to automate... 04-13-2015, 05:11 AM
jungleskipper1 Re: Button to automate... 04-13-2015, 11:39 AM
john55 Re: Button to automate... 04-13-2015, 12:27 PM
john55 Re: Button to automate... 04-19-2015, 08:47 AM
  1. #1
    Registered User
    Join Date
    01-16-2015
    Location
    Chesapeake, VA
    MS-Off Ver
    2013
    Posts
    18

    Button to automate sending two different worksheets as attachments via same email

    I am using Excel 2013 and have a project that needs to send out, via email, two different worksheets from the same workbook. The worksheets are named "Weekly Report" and "Weekly Overview". I have placed a button "Send Report" on the worksheet "Weekly Overview". Can you assist me with a macro that will send the two worksheets as attachments to two individual people when the "Send Report" button is pushed? The people will always be the same recipients.
    Thanks, in advance, for your help.

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Button to automate sending two different worksheets as attachments via same email

    try this
    Sub Button1_Click()
    'save it
    ThisWorkbook.Save
    'by Norie
       Dim OutApp As Object
        Dim OutMail As Object
        Dim wbTemp As Workbook
        Dim strFilename As String
        
       
       ' ThisWorkbook.Worksheets("Sheet2").Copy
       ThisWorkbook.Sheets(Array("Weekly Report", "Weekly Overview")).Copy
        
        ' set reference to new workbook
        Set wbTemp = ActiveWorkbook
        
        ' save new workbook so it can be sent as attachment
        
        wbTemp.SaveAs ThisWorkbook.Path & "/" & "Weekly Report" & " " & "and" & " " & "Weekly Overview", FileFormat:=56 'XlFileFormat.xlOpenXMLWorkbook
        
        strFilename = wbTemp.FullName
        
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        'On Error Resume Next
        With OutMail
            .To = "aaaa@yahoo.com" & ";" & "bbb@yahoo.com"
            .Subject = "whatever..."
            .Body = "Hello"
                    
            .Attachments.Add strFilename
            .display
        End With
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
        
        wbTemp.Close
        
        Kill strFilename
        
    End Sub
    Regards, John55
    If you have issues with Code I've provided, I appreciate your feedback.
    In the event Code provided resolves your issue, please mark your Thread as SOLVED.
    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

    ...enjoy -funny parrots-

  3. #3
    Registered User
    Join Date
    01-16-2015
    Location
    Chesapeake, VA
    MS-Off Ver
    2013
    Posts
    18

    Re: Button to automate sending two different worksheets as attachments via same email

    Thanks so much for your help. Everything worked fine with the exception of the two attached warnings:
    Excel Warning One.jpg Excel Warning Two.jpg.
    Is there any way around these messages?
    Thank you-

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Button to automate sending two different worksheets as attachments via same email

    Hi,
    I do not encounter this warning (I have a small test file), read this https://msdn.microsoft.com/en-us/lib.../ff839782.aspx and try after you create a test file
    '
    '
      ' save new workbook so it can be sent as attachment
        Application.DisplayAlerts = False
        wbTemp.SaveAs ThisWorkbook.Path & "/" & "Weekly Report" & " " & "and" & " " & "Weekly Overview", FileFormat:=56 'XlFileFormat.xlOpenXMLWorkbook
        
        strFilename = wbTemp.FullName
        
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        'On Error Resume Next
        With OutMail
            .To = "aaaa@yahoo.com" & ";" & "bbb@yahoo.com"
            .CC = ""
            .BCC = ""
            .Subject = "whatever..."
            .Body = "Hello"
                    
            .Attachments.Add strFilename
            .display
        End With
        On Error GoTo 0
        Set OutMail = Nothing
        Set OutApp = Nothing
        
        wbTemp.Close
        
        Kill strFilename
      Application.DisplayAlerts = True
    End Sub

  5. #5
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel for Microsoft 365
    Posts
    2,060

    Re: Button to automate sending two different worksheets as attachments via same email

    hi,
    glad you are happy with the solution provided, thank you for the rep! the credit has to go to Norie!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Sending Email Attachments by Data
    By Adzg91 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-24-2014, 10:34 AM
  2. Sending Email with Multiple Attachments from Excel
    By Lisa4legin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-29-2013, 03:24 PM
  3. button to email and button to add attachments
    By ea223 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-23-2013, 01:33 PM
  4. Replies: 0
    Last Post: 09-22-2012, 10:06 AM
  5. email attachments of separate worksheets
    By tarmon in forum Excel General
    Replies: 0
    Last Post: 06-29-2012, 10:59 AM

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