Monday, October 14, 2013

Email Using VBA., Part I: Keeping the Sig Alive

By  "the Sig" I mean the Outlook signature, not the enigmatic character on BBC's Top Gear.

I noticed that when I ran my VBA code to create an email, the signature would disappear sometimes.  I followed my usual pattern of create then display.

    'RecipientsCopiesToSubj and Msg are all optional String parameters to the subroutine.
    Set appOutlook = New Outlook.Application
    Set EmailItem = appOutlook.CreateItem(olMailItem)
    
    With EmailItem     
        .To = Recipients
        .CC = CopiesTo
        .Subject = Subj
        .HTMLBody = Msg & "</p>" & EmailItem.HTMLBody
       .Display 
    End With

To see what was happening I moved the .Display to the top of the list.  The signature was there, and remained there, throughout.  Anytime I moved .Display after .HTMLBody the signature was wiped out

    With EmailItem     
        .Display         
        .To = Recipients
        .CC = CopiesTo
        .Subject = Subj
        .HTMLBody = Msg & "</p>" & EmailItem.HTMLBody       
    End With

No comments:

Post a Comment