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.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
user3794203
  • 205
  • 2
  • 7
  • 23

1 Answers1

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;">
NickyTheWrench
  • 3,150
  • 1
  • 23
  • 35
  • 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? – user3794203 Sep 21 '15 at 18:55
  • 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. – NickyTheWrench Sep 22 '15 at 14:59
  • 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. – user3794203 Sep 22 '15 at 18:10