Macro to Email several sheets, but not to email those where A2 is blank

Status
Not open for further replies.

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
i am creating a new post as I could not edit the previous post

I have macro to email several sheets, but do not want to attach those sheets where A2 is blank


It would be appreciated if someone could amend my code

Code:
 Sub Email_salesheets()



Dim Ztext As String

Dim Zsubject As String







Ztext = [bodytext] 'read in text from named cell

Zsubject = [SubjectText]



Sheets(Array("sales1", "sales2", "sales3")).Copy



With Range("A1:O150")

.Value = .Value

End With



With ActiveWorkbook

'.Windows(1).Visible = False

Application.DisplayAlerts = False

.SaveAs Environ("TMP") & "\" & ThisWorkbook.Sheets("sales1").Name & ".xlsx"



Application.DisplayAlerts = True

.Close (True)

End With



With CreateObject("Outlook.Application").CreateItem(0)

.To = Join(Application.Transpose(Sheets("Email sales").Range("AA1:AA3").Value), ";")

.Subject = Zsubject

.Body = Ztext



.Attachments.Add Environ("TMP") & "\" & ThisWorkbook.Sheets("sales1").Name & ".xlsx"

.Display

'.send

End With



End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Status
Not open for further replies.

Forum statistics

Threads
1,214,817
Messages
6,121,717
Members
449,050
Latest member
MiguekHeka

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