email & attachment

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
675
Office Version
  1. 365
Platform
  1. Windows
good evening,

can someone help me with some VB to send to a certain email (ie me@me.com) and attach the worksheet (sheet1)

Thank you all for your time and assistance.

KR
trevor3007
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
This should work only with the OUTLOOK client, not the Web Version of Outlook.
I would not use the ".TO = ..." line myself so that it remains more flexible. I did add it so you would see how.
This macro makes the creation and attaching of the new file from the sheet easy.
I use the .Display method instead which allows for any additional comments to be added as well as assigning the receivers. Using the .Send would mean it would send immediately. You could use .Save which creates a draft message.


Code:
Sub EmailActiveWorksheet()

Dim OutlookApp As Outlook.Application
Dim DisplayStatusBar As Boolean
Dim DestinationPath As Variant
Dim fileName As String
Dim NewFileName As String
Dim ws As Worksheet

Set ws = ActiveWorkbook.Worksheets(ActiveSheet.Name)
NewFileName = ActiveSheet.Name & ".xlsx"


    ActiveWorkbook.Worksheets(ActiveSheet.Name).Copy
    ActiveWorkbook.Worksheets(ActiveSheet.Name).SaveAs "C:\TempM\" & NewFileName
    ActiveWorkbook.Close False
    
'Set Email Info
    Set OutlookApp = New Outlook.Application
      Msg = "Dear " & Recipient & vbCrLf & vbCrLf _
        & "Here's a copy Worksheet " _
        & "" _
        & "" & vbCrLf & vbCrLf _
        & "Thanks for your help." ' demonstrates internal carriage return line feed
        
'Create Mail Item and send it
      Set MItem = OutlookApp.CreateItem(olMailItem)
      With MItem
        '.To = WS.Range("A1").Value  ' Each worksheet to be sent should have
                                    ' SendTo Email information in Cell A1
                                    ' Multiple Email addresses seperated
                                    ' By semi-colons.
        .Subject = "WorkSheet Copy "
        .Body = Msg
        .To = "me@me.com"
        .Attachments.Add ("C:\TempM\" & NewFileName)
        '.Send 'Send immediately
        .Display 'Save to Drafts folder
      End With
      Kill "C:\TempM\" & NewFileName ' Deletes Each filename after use.
                        ' To keep files comment out the Kill statement.



End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top