1

I have completed this code to populate the body of an Outlook email, however, I do not know how I can use my existing signature block already created in Outlook. When I create a new, reply or forward email, my signature is there, but when I create the email with this code it does not appear. What I'm trying to accomplish here is to have my signature (or any signature for that matter) appear into the email created by this code.

Sample email with desired signature

    Private Sub emailbutton_Click()
    'No-option email sending
    Dim OL              As Object
    Dim EmailItem       As Object
    Dim Doc             As Document

    Application.ScreenUpdating = False
    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(olMailItem)
    Set Doc = ActiveDocument


    If VName.Value = "" Then
        Doc.SaveAs ("Quotation_Blank 2016")
    Else
       Doc.SaveAs2 ("QFORM" & "_" & JNumber.Value & "_" & VName.Value)

    End If


    With EmailItem
        .Subject = "QFORM" & "_" & JNumber.Value & "_" & VName.Value

        'HTMLbody
        msg = "<b><font face=""Times New Roman"" size=""3"" color=""blue"">INTEGRATED ASSEMBLY </font></b><br>" _
        & "   1200 Woodruff Rd.<br>" _
        & "   Suite A12<br>" _
        & "   Greenville, SC 29607<br><br>" _
        & "We have recently released subject project, which will contain assemblies to be outsourced. You have been selected to build these assemblies according to the attachment.<br><br>" _
        & "As part of this process, please review the quotion form attached and inidcate your acceptance. If adjustments and-or corrections are required please feel free to contact us for quick resolution.<br><br>" _
        & "<b><font face=""Times New Roman"" size=""3"" color=""Red"">NOTE: </font></b>" _
        & "The information on attached quotation form is not a contract and only an estimate of predetermined costs per hourly rate for outsource assemblies. <br><br>" _
        & "*******For your records you may wish to print out the completed quote form. <br><br>" _
        & "Thank you, <br><br>" _
        & "<b>HARTNESS INTERNATIONAL </b><br>" _
        & "H1 Production Control" & vbNewLine & Signature


        .HTMLBody = msg

        If VName.Value = "INTEGRATED ASSEMBLY" Then
            .To = "XXX.com;"
            .CC = "XXX.com;" & "XXX.com;"
            .Importance = olImportanceNormal 'Or olImportanceHigh Or         olImportanceLow
            .Attachments.Add Doc.FullName
            .Display
         ElseIf VName.Value = "LEWALLEN" Then
            .To = "XXX.com;"
            .CC = "XXX.com;" & "XXX.com;"
            .Importance = olImportanceNormal 'Or olImportanceHigh Or         olImportanceLow
            .Attachments.Add Doc.FullName
            .Display

         End If
    End With

    Application.ScreenUpdating = True

    Set Doc = Nothing
    Set OL = Nothing
    Set EmailItem = Nothing
End Sub
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Rey Taino
  • 179
  • 1
  • 4
  • 18

3 Answers3

0

I think you need to call the .HTMLBody again after you insert msg.

So for example:

.HTMLBody = msg & .HTMLBody

Should get the signature. I'm not deep enough into programming to know why though.

mike vervair
  • 33
  • 1
  • 6
  • I called the .HTMLBody with msg, but it did not input the signature. There was not change on how the email executed in Outlook. Either way, Thanks for the suggestion. – Rey Taino Aug 10 '16 at 17:00
0

Do you have Option Explicit set in your module?

I don't see where you've set Signature or declared it so it's probably empty and not giving you an error message.

I think you need to retrieve it first by pulling in the blank Body

Something like this should work

With EmailItem
   .Display
   signature = .body
   .Subject = "QFORM" & "_" & JNumber.Value & "_" & VName.Value
' and so on ..

`

dbmitch
  • 5,361
  • 4
  • 24
  • 38
  • Dbmitch, I just seen your message. I was doing exactly and posted my answer – Rey Taino Aug 10 '16 at 17:33
  • It did not work at first. I had to recall the .HTMLBody with my message as suggested by the first vervair in the first comment to make it all work. Thanks to all for your help. – Rey Taino Aug 10 '16 at 17:34
0

The code was successful with inputting a with statement to display the EmailItem - along with recalling .HTMLBody following the msg.. Please see full code below.

Private Sub emailbutton_Click()
    'No-option email sending
    Dim OL              As Object
    Dim EmailItem       As Object
    Dim Doc             As Document

    Application.ScreenUpdating = False
    Set OL = CreateObject("Outlook.Application")
    Set EmailItem = OL.CreateItem(olMailItem)
    Set Doc = ActiveDocument

   With EmailItem
    .Display
    End With
        Signature = EmailItem.body


    With EmailItem
        .Subject = "QFORM" & "_" & JNumber.Value & "_" & VName.Value

        'HTMLbody
        msg = "<b><font face=""Times New Roman"" size=""4"" color=""blue"">INTEGRATED ASSEMBLY </font></b><br>" _
        & "   1200 Woodruff Rd.<br>" _
        & "   Suite A12<br>" _
        & "   Greenville, SC 29607<br><br>" _
        & "We have recently released subject project, which will contain assemblies to be outsourced. You have been selected to build these assemblies according to the attachment. <br><br>" _
        & "As part of this process, please review the quotation form attached and indicate your acceptance. If adjustments and-or corrections are required, please feel free to contact us for quick resolution. <br><br>" _
        & "<b><font face=""Times New Roman"" size=""4"" color=""Red"">NOTE: </font></b>" _
        & "The information on attached quotation form is not a contract and only an estimate of predetermined costs per hourly rate for outsource assemblies. <br><br>" _
        & "*******For your records you may wish to print out the completed quote form. <br><br>" _
        & "Thank you, <br><br>" _
        & "<b>HARTNESS INTERNATIONAL </b><br>" _
        & "H1 Production Control <br>" _
        & vbNewLine & Signature

        .HTMLBody = msg & .HTMLBody

        If VName.Value = "INTEGRATED ASSEMBLY" Then
            .To = "ryan@integratedassembly.com;"
            .CC = "jfournier@hartness.com;" & "jmarshone@hartness.com;"
            .Importance = olImportanceNormal 'Or olImportanceHigh Or         olImportanceLow
            .Attachments.Add Doc.FullName
            .Display
         ElseIf VName.Value = "LEWALLEN" Then
            .To = "jessica.andrews@patriot-automation.com;"
            .CC = "jfournier@hartness.com;" & "jmarshone@hartness.com;"
            .Importance = olImportanceNormal 'Or olImportanceHigh Or         olImportanceLow
            .Attachments.Add Doc.FullName
            .Display

         End If
    End With


    If VName.Value = "" Then
        Doc.SaveAs ("Quotation_Blank 2016")
    Else
       Doc.SaveAs2 ("QFORM" & "_" & JNumber.Value & "_" & VName.Value)

    End If

    Application.ScreenUpdating = True

    Set Doc = Nothing
    Set OL = Nothing
    Set EmailItem = Nothing
End Sub
Rey Taino
  • 179
  • 1
  • 4
  • 18