Default Signature at end of Excel generated email

2Took

Board Regular
Joined
Jun 13, 2022
Messages
203
Office Version
  1. 365
Platform
  1. Windows
Below code works, except that instead of a Signature that I have designated as default in Outlook to be added to all my emails, this code picks another signature.

- How do I fix it for it to pick a Signature that I have designated as default in Outlook to be added to all my emails?

Playing with numbers in this part of the code does not do the trick: "OpenAsTextStream(1, -2)"

VBA Code:
Dim OutApp As Object, OutMail As Object, LogFile As String
Dim cell As Range, S As String, WMBody As String, lFile As Long

S = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(S, vbDirectory) <> vbNullString Then S = S & Dir$(S & "*.htm") Else S = ""
S = CreateObject("Scripting.FileSystemObject").GetFile(S).OpenAsTextStream(1, -2).ReadAll

And then I append & S at the end of "EmailItem.HTMLBody = "
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
If the signature loads up when you create mails automatically then you can capture it by displaying the mail first, grab the sig then place it on the end of the mail.

Try the below:
VBA Code:
Sub test()
    Dim OApp As Object, OMail As Object, signature As String
    
    Set OApp = CreateObject("Outlook.Application")
    Set OMail = OApp.CreateItem(0)
    
    With OMail
        .Display
    End With
    
    signature = OMail.HTMLBody
    With OMail
        .To = "someone@somedomain.com"
        .Subject = "Email subject here"
        .HTMLBody = "Add body text here" & vbNewLine & signature
        '.Send
    End With
    
    Set OMail = Nothing
    Set OApp = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,492
Members
448,967
Latest member
visheshkotha

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