Adding a signature to Outlook email

mikenelena

Board Regular
Joined
Mar 5, 2018
Messages
139
Office Version
  1. 365
Platform
  1. Windows
My code is stripping out the e-mail signature at the line that adds the e-mail body text. The signature includes a small graphic, so that should be HTML. I've been fooling with this code for hours trying suggestions from many internet threads. Essentially we want to attach all PDF invoice files from a folder named for the recipient. Everything works but the signature, and the VBNewLine spacing. I am not committed to the particular style of this code. It is only what I've cobbled together from multiple online resources. If there is a more efficient way to code this that achieves what we need, I'm happy to use it. Thanks in advance for any help this group can offer!

VBA Code:
Private Sub cmdSendInvoices_Click()

Dim appOL As Outlook.Application
Dim MailOL As Object
Dim strBody As String
Dim strPath, strFileName As String
Dim fsFolder As Object
Dim fsFile As Object
Dim Pattern As String
Dim SSignature As String
Dim Adjuster As String

Dim Size As Integer
Size = Me.ctrlListBox.ListCount - 1
ReDim ListBoxContents(0 To Size) As String
Dim i As Integer

For i = 0 To Size
    ListBoxContents(i) = Me.ctrlListBox.ItemData(i)
Next i

For i = 0 To Size

Set appOL = GetObject(, "Outlook.Application")
Set MailOL = appOL.CreateItem(olMailItem)

Adjuster = DLookup("[AdjusterFirst]", "qryEmailFinal", "[Adjuster Full Name] = '" & ListBoxContents(i) & "'")

strBody = Adjuster & "," & vbNewLine & _
"The attached invoice(s) show as outstanding in our system.  Could we trouble you to check the payment status for us when you have a moment?  Please confirm you have received this e-mail."

With MailOL

strPath = "S:\OurPath\" & ListBoxContents(i) & "\"

Pattern = strPath & "*" & ".*"

strFileName = Dir(Pattern)

Do While strFileName <> ""
.Display
.To = DLookup("[Email]", "qryEmailFinal", "[Adjuster Full Name] = '" & ListBoxContents(i) & "'")
.Subject = "Overdue Invoices"
'.BodyFormat = olFormatHTML
.HTMLBody = strBody & vbNewLine & SSignature

.Attachments.Add strPath & strFileName
strFileName = Dir

Loop

End With

Next i

Set appOL = Nothing
Set MailOL = Nothing

End Sub
 
Do let us know how it goes.
I do not remember why I thought I had to split it. Perhaps it was because I did not want to display multiple messages all the time? :unsure:

Would be interesting to know, if only for the odd email.?
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I'm going to let Gasman carry on with this one seeing as how I mentioned I haven't created emails with signatures. I could only weigh in where the code doesn't look right and offer suggestions on basic troubleshooting, not the least of which is to step through code ! :)
Last but not least would be to consider re-writing your code so that the function doesn't get the same signature multiple times (if that is applicable, which you didn't comment on).
 
Upvote 0
I'm going to let Gasman carry on with this one seeing as how I mentioned I haven't created emails with signatures. I could only weigh in where the code doesn't look right and offer suggestions on basic troubleshooting, not the least of which is to step through code ! :)
Last but not least would be to consider re-writing your code so that the function doesn't get the same signature multiple times (if that is applicable, which you didn't comment on).
Yes,
I only get it once at the start, split it, then sandwich my email content between the header and footer.?
 
Upvote 0
I'm going to let Gasman carry on with this one seeing as how I mentioned I haven't created emails with signatures. I could only weigh in where the code doesn't look right and offer suggestions on basic troubleshooting, not the least of which is to step through code ! :)
Last but not least would be to consider re-writing your code so that the function doesn't get the same signature multiple times (if that is applicable, which you didn't comment on).
Hi Micron,

Thanks for the help with this... It will in fact be the same signature in this loop, so I'll definitely be taking your suggestion on that. I think what I'll do this afternoon is try to rewrite the entire procedure, simply, with as few lines as possible. If I can get the signature working, I can then add back in the loops, etc. Might make troubleshooting it a bit easier.
 
Upvote 0
If you get it working, just use the function to return the signature to a variable before entering the loop then use that variable in the loop that sends multiple emails.
 
Upvote 0
Yes,
I only get it once at the start, split it, then sandwich my email content between the header and footer.?
I considered this, but on further reading discovered that newer versions of Outlook will require the signature graphic to accompany the e-mail as an attachment. Unfortunately that will not work for us. Looks like this one will remain an unsolved mystery for now, but certainly not for lack of effort by Micron and welshgasman. Many thanks to you both for your efforts on this!
 
Upvote 0
Ah, so that is why I sometimes get the graphic in the email also as an attachment?

Well you know where the graphic is located, so you can attach that as normal on each message? if it is a requirement.
I'm sure Outlook just does that itself? I cannot see the people from whom I have emails like that doing that each time?

Good luck anyway.
 
Upvote 0
Ah, so that is why I sometimes get the graphic in the email also as an attachment?

Well you know where the graphic is located, so you can attach that as normal on each message? if it is a requirement.
I'm sure Outlook just does that itself? I cannot see the people from whom I have emails like that doing that each time?

Good luck anyway.
Yes, I think you are correct - Outlook does it by itself. But it looks tacky, and simply won't work for us. I'll circle back to this issue after some time. Maybe someone will eventually stumble on something that will work.
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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