+ Reply to Thread
Results 1 to 2 of 2

macro to send an email with an active excel sheet attached

  1. #1
    Registered User
    Join Date
    04-23-2008
    Posts
    50

    macro to send an email with an active excel sheet attached

    Hello,

    Could anyone help me to modify the below vba code? It sends an email with an attachment right away after pressing the macro button. I would like the user to see the email in outlook before it gets send... and then press 'send' in Outlook...I would appreciate your help. Many thanks.


    Sub Mail_ActiveSheet()
    'Working in Excel 2000-2013
    'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object

    With Application
    .ScreenUpdating = False
    .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    'Copy the ActiveSheet to a new workbook
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
    If Val(Application.Version) < 12 Then
    'You use Excel 97-2003
    FileExtStr = ".xls": FileFormatNum = -4143
    Else
    'You use Excel 2007-2013
    Select Case Sourcewb.FileFormat
    Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
    Case 52:
    If .HasVBProject Then
    FileExtStr = ".xlsm": FileFormatNum = 52
    Else
    FileExtStr = ".xlsx": FileFormatNum = 51
    End If
    Case 56: FileExtStr = ".xls": FileFormatNum = 56
    Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
    End Select
    End If
    End With

    ' 'Change all cells in the worksheet to values if you want
    ' With Destwb.Sheets(1).UsedRange
    ' .Cells.Copy
    ' .Cells.PasteSpecial xlPasteValues
    ' .Cells(1).Select
    ' End With
    ' Application.CutCopyMode = False

    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With Destwb
    .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
    On Error Resume Next
    With OutMail
    .to = "[email protected]"
    .CC = ""
    .BCC = ""
    .Subject = "This is the Subject line"
    .Body = "Hi there"
    .Attachments.Add Destwb.FullName
    'You can add other files also like this
    '.Attachments.Add ("C:\test.txt")
    .Send 'or use .Display
    End With
    On Error GoTo 0
    .Close savechanges:=False
    End With

    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
    .ScreenUpdating = True
    .EnableEvents = True
    End With
    End Sub

  2. #2
    Forum Contributor
    Join Date
    03-12-2013
    Location
    Chicago, USA
    MS-Off Ver
    Excel 2007
    Posts
    230

    Re: macro to send an email with an active excel sheet attached

    Change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

+ 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. [SOLVED] Excel Macro lotus notes email clear attached sheet
    By johnny_w in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-02-2013, 08:24 AM
  2. Send excel file attached in email
    By vijanand1279 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-06-2013, 03:55 AM
  3. Send Email From Active Sheet
    By dentdntn in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-02-2012, 05:23 AM
  4. Find email address & send active sheet.
    By JSB0009 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-14-2010, 02:07 AM
  5. Send Email (Active Sheet)
    By Murtaza in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-25-2005, 09:06 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