1

I currently have a spreadsheet that I use to generate mass e-mails that I can format using HTML and it works really well. One thing that I have not been able to figure out is whether or not there is a way to also incorporate CSS styling within an HTML e-mail created through excel.

Has anyone tried this/had success with this before?

My current subroutine uses the Outlook Application to construct material into an HTML email. The code for calling/constructing is:

Sub Test_Email(what_address As String, subject_line As String, mail_body_message As String)
Dim olApp As Outlook.Application
Dim oAttatch As Outlook.Attachment

Set olApp = CreateObject("Outlook.Application")

Dim olMail As Outlook.MailItem

Set olMail = olApp.CreateItem(olMailItem)

With olMail

.To = what_address

.Subject = "My Subject"

.BodyFormat = olFormatHTML

.HTMLBody = mail_body_message
'mail_body_message is all text that resides in Cell A1 and it consists of body text of the email as well as the HTML tags that I use to organize the message display
.Display
End With
End Sub

Within cell A1, I have all of my message information. Starts with and ends with <HTML> </HTML> and then my message body resides within the tags. So far, when I have tried to insert CSS styles within the existing HTML in cell A1, it spits out the HTML just fine but treats the CSS as text.

3
  • You will need to add details describing exactly how you currently create these emails... Commented Sep 21, 2015 at 17:44
  • Thank you, Tim. I updated my OP. Commented Sep 21, 2015 at 18:04
  • stackoverflow.com/questions/4829254/… Commented Sep 21, 2015 at 18:41

1 Answer 1

1

You'll need to use inline CSS.

For example:

<img src="http://example.com/foo.jpg" style="max-width:100px;">

Or

<a href="http://example.com" style="color:#000;">
Sign up to request clarification or add additional context in comments.

3 Comments

Currently, when I use the inline HTML for inserting a button, this method does not appear to be functioning. Any thought on how this can be accomplished?
So you are typing HTML directly within cell A1, and cell A1 is the body of the email? You included inline css within the HTML inside cell A1, however it is not working? Just trying to understand better.
Yes, correct. Using HTML I can alter the output of the message by changing things within cell A1 (using HTML tags) however, when I try to include inline CSS for an HTML button, this appears not to be supported. I was not sure if anyone else had ever attempted this and if there was some additional reference library that I would need to enable to support it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.