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

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,215,200
Messages
6,123,611
Members
449,109
Latest member
Sebas8956

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