Add system Signature to email and set Direct Replies To, to exclude sender

2Took

Board Regular
Joined
Jun 13, 2022
Messages
203
Office Version
  1. 365
Platform
  1. Windows
Hi,

1. My attempt to include my default Outlook signature with email generated from Excel is not working. How do I modify this existing code, that does everything else I need, to add the signature?
2. How do I also modify this existing code, that does everything else I need, to set Direct Replies To, to exclude sender. Or to include only those in To, CC, BCC fields - without actually relisting their e-addresses by hardcoding them, but instead for VBA to include them by whomever happened to be in the sent email in those fields?


VBA Code:
Sub email() 'attaches active workbook to a generated email

Dim EmailApp As Outlook.Application
Dim Source As String
Set EmailApp = New Outlook.Application
Dim EmailItem As Outlook.MailItem
Set EmailItem = EmailApp.CreateItem(olMailItem)
'
Signature = EmailItem.HTMLBody
'
EmailItem.To = "John@abc.com”
EmailItem.CC = "Jane@abc.com"
EmailItem.BCC = ""
EmailItem.Subject = ActiveWorkbook.Name
EmailItem.HTMLBody = "Hello,<br><br>" & "There are NumOfRows, ZZZZZ of them.<br><br>" & _
"Please...<br><br>" & _
"ABC.<br><br>" & "Thanks." & Signature

'replacing strings
Dim X As Integer
X = Range("a2").End(xlDown).Row - 1
EmailItem.HTMLBody = Replace(EmailItem.HTMLBody, "NumOfRows", X)
'
Dim Y As Integer
'Y = WorksheetFunction.CountIf(Range("a2").End(xlDown).Value, >10)
Y = Application.WorksheetFunction.CountIf(Range("A:A"), ">10")
EmailItem.HTMLBody = Replace(EmailItem.HTMLBody, "ZZZZZ", Y)
'

Source = ActiveWorkbook.FullName
EmailItem.Attachments.Add Source

EmailItem.Display

'EmailItem.Send

End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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