mardi 19 juillet 2016

IF statements within .HTMLBody (VBA)

Users will input answers through a userform, then an email summary of the responses will be sent. Several questions in the userform are optional.

In the .HMTLBody section, I would like certain responses to be emailed in red text if they were answered (they normally aren't, so I want it to be easy to spot).

Is there a way to use a conditional statement to format certain fields within the .HTMLBody section? (IIF?)

Sample below ("Business Unit" field optional).

Thank you.

Dim EmailBody as String

EmailBody = "Unit Name: " & UCase(Me.ttbUnitName.Value) & “<br>” _
    & "Nation: " & UCase(Me.cbxNation.Value) & “<br>” _
    & "State: " & UCase(Me.cbxState.Value) & “<br>” _
    & "County: " & UCase(Me.cbxCounty.Value) & “<br>” _
    & "Business Unit: " & UCase(Me.ttbBusinessUnit.Value)

   With MItem
        .To = "123@fake.com"
        .CC = myEmail
        .DeferredDeliveryTime = SendAt
        .Subject = Me.Name & " Submission"
        .HTMLBody = EmailBody
   End With

Aucun commentaire:

Enregistrer un commentaire