Excel VBA Code sending email from active workbook except for 1 sheet

EmilVictor

New member
Joined
Oct 15, 2018
Messages
5
Reaction score
0
Points
0
Excel Version(s)
2012
here is my code so far. it sends all the excel file. but I need 1 sheet to be excluded.

Code:
Dim OutApp As Object
 Dim OutMail As Object
 
 Set OutApp = CreateObject("Outlook.Application")
 Set OutMail = OutApp.CreateItem(0)
  
  
 On Error Resume Next
 With OutMail
 .To = 
 .CC = 
 .BCC = ""
 .Subject = ActiveWorkbook.Name
 .body = "Hi" & vbNewLine & vbNewLine & _
 .Attachments.Add ActiveWorkbook.FullName
 .Display
 End With
 On Error GoTo 0

so like I have 5 sheets.

I just need 4 sheets to be send to email.

like sheet1 and sheet 2 and sheet and sheet 4 without sheet 5



 
 Set OutMail = Nothing
 Set OutApp = Nothing
 
Last edited by a moderator:
Hi
could you please wrap your code with code tags in the future? ( click Go advanced - select code - click the # button - or add the HTML tags manually); Thanks
 
.
This macro will save the selected worksheets into a single workbook. You select the TABS to be included in the new workbook.

Code:
Option Explicit


Sub CopySelectedSheets()
     
    ActiveWindow.SelectedSheets.Copy
     
End Sub


This macro will send an email and allow you to select a file to be attached :

Code:
Option Explicit

Sub SendEmail()
   
    Dim xStrFile As String
    Dim xFilePath As String
    Dim xFileDlg As FileDialog
    Dim xFileDlgItem As Variant
    Dim xOutApp
    Dim xMailOut
    Application.ScreenUpdating = False
    Set xOutApp = CreateObject("Outlook.Application")
    Set xMailOut = xOutApp.CreateItem(olMailItem)
    Set xFileDlg = Application.FileDialog(msoFileDialogFilePicker)
    If xFileDlg.Show = -1 Then
        With xMailOut
            .To = "my@163.com"
            .Subject = "test"
            .Body = "test"
            For Each xFileDlgItem In xFileDlg.SelectedItems
                .Attachments.Add xFileDlgItem
            Next xFileDlgItem
            .Display
        End With
    End If
    Set xMailOut = Nothing
    Set xOutApp = Nothing
    Application.ScreenUpdating = True


End Sub
 

Attachments

  • Works - Email w FileDialog Attachments.xlsm
    15.5 KB · Views: 12
  • Create New Workbook with Select Sheets.xlsm
    14.3 KB · Views: 13
Back
Top