Add a dynamic signature in VBA

QMAN223

New Member
Joined
Nov 24, 2021
Messages
36
Office Version
  1. 365
Platform
  1. Windows
I would like to add a dynamic signature in VBA whenever someone opens the distribution list to send an emails out to people.

Scenario:

IF I OPEN the distribution list, the email will be created and it will have MY Signature on to the Body of the email.

If someone ELSE opens the distribution list, their Email Signature is added to the Body of the email.

Here is the code I'm working with:

Sub Send_Email_With_Attachment()

Dim emailApplication As Object
Dim emailItem As Object


Set emailApplication = CreateObject("Outlook.Application")
Set emailItem = emailApplication.CreateItem(0)

'Date Update in Subject Line

Dim lastSunday As Date
lastSunday = DateAdd("d", 1 - Weekday(Now), Now)

'Now build the email.

emailItem.To = Range("A2").Value

emailItem.CC = Range("B2").Value

emailItem.body = "Dear All" & vbCrLf & vbCrLf & "Please find attached the Weekly Training report." & vbCrLf & vbCrLf & "Kind Regards,"

'Send the email
emailItem.Display
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Do you want to use for users outlook signature? What do you mean by 'My signature' and 'their signature'?
 
Upvote 0
So, depending on who's logged in and accessed the distribution list, the macro should automatically put their signature in the body.
 
Upvote 0
So I assume that you mean outlook's signature.
Problem can appear when users has differently named their signatures. Usually in companies signatures have the same names. Try.

Add these into a code:

VBA Code:
'Change file name of .htm document of your signature
    SigString = Environ("appdata") & "\Microsoft\Signatures\This_Name_Have_to_be_adapt.htm"
    If Dir(SigString) <> "" Then
        Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If
then

VBA Code:
emailItem.htmlbody = emailItem.body & Signature

p.s. put this into vba code as well (it is necessary)
VBA Code:
Function GetBoiler(ByVal sFile As String) As String
'**** Kusleika
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function
 
Upvote 0
Solution

Forum statistics

Threads
1,215,043
Messages
6,122,822
Members
449,096
Latest member
Erald

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