Sending 2 Worksheets via email

WxShady13

Board Regular
Joined
Jul 24, 2018
Messages
184
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have a workbook that has several worksheets tracking data. I currently have the code to send 1 worksheet and a button located on that sheet. How do I tweak the code to send both sheets in one email?

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

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I have a macro that I would use to send selected sheets individually.
I have modified that to be very close to what you are looking for.
It creates a draft message and opens it so you can review and modify the email before actually sending.

Code:
Sub Send_as1_Draft_Worksheets()
    ' Public item Dim ws As Worksheet
    Dim OutlookApp As Outlook.Application
    Dim DisplayStatusBar As Boolean
    Dim DestinationPath As Variant
    Dim ws As Variant
    
    DisplayStatusBar = Application.DisplayStatusBar
    Application.DisplayStatusBar = True
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Application.StatusBar = ActiveWindow.SelectedSheets.Count & " Remaining Sheets"
    
    'For Each ws In ActiveWindow.SelectedSheets
    With ActiveWindow.SelectedSheets
        Dim NewFileName As String
    'ws.Select
    NewFileName = "C:\temp\" & "Tracking Data" & ".xlsx"
    .Copy
    ' The macro over writes any previous file.
    ActiveWorkbook.SaveAs fileName:=NewFileName, _
        FileFormat:=xlOpenXMLWorkbook
    ActiveWorkbook.Close SaveChanges:=False
'Set Email Info
    Set OutlookApp = New Outlook.Application
'      Msg = "Dear " & Recipient & vbCrLf & vbCrLf _
'        & "Here's a copy of the .... " _
'        & "--- " _
'        & ",,,," & vbCrLf & vbCrLf _
'        & "Thanks for your help."
'
    Msg = "Predefined message Text"
'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 = "Shrink Or Gross Profit Inventory Reporting"
        .Body = Msg
        .Attachments.Add (NewFileName)
        '.Send 'Send immediately
        .Display 'Save to Drafts folder
      End With
      Kill NewFileName  ' Deletes Each filename after use.
                        ' To keep files comment out the Kill statement.
End With
'Next
    Application.DisplayAlerts = True
    Application.StatusBar = False
    Application.DisplayStatusBar = DisplayStatusBar
    Application.ScreenUpdating = True
    Close 'close all files and folders?
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,400
Members
449,156
Latest member
LSchleppi

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