Reputation: 75
I'm trying to remove a space after the bolded "Header" and before my "bullets" in my HTML email within VBA. I've included my code and a picture of its output below. I've seen posts using CSS in HTML but I'm not sure how to access that through VBA... Help would be appreciated!
With OMail
.Display
End With
signature = OMail.HTMLbody
With OMail
.Subject = "Subject"
.HTMLbody = "<style> ul {margin-top:0px;} li {margin-left:10px;}</style> " _
& "Unbulleted Text" _
& "<br>" & "<br>" & "<b>Header</b>" _
& "<ul>" & "<li>" & "bullet one" _
& "</li>" & "<li>" & "bullet two" _
& "</li>" & "<li>" & "bullet three" _
& "</li>" & "</ul>" & "Unbulleted Text"
End With
The above code has been modified to represent proposed solutions below, however the result is still the same (see picture)
Upvotes: 0
Views: 1339
Reputation: 511
If you add a margin-top:0px; to your li it did the trick for me. Not sure why it didn't inherit the setting from the ul but it fixes your issue at least :)
.HTMLBody = "<style> ul {margin-top:0px;} li {margin-left:50px;margin-top:0px;}</style> " _
& "Unbulleted Text" _
& "<br>" & "<br>" & "<b>Header</b>" _
& "<ul>" & "<li>" & "bullet one" _
& "</li>" & "<li>" & "bullet two" _
& "</li>" & "<li>" & "bullet three" _
& "</li>" & "</ul>" & "Unbulleted Text"
Upvotes: 1
Reputation: 11755
Add CSS/Styles it like any other string.
In this case you want to remove the margin from your ul
element:
"<style> ul {margin:0px;} </style>"
If you dont want to remove the bottom margin too, then use this:
"<style> ul {margin-top:0px;} </style>"
If it's affecting the li
elements for some reason, try using this:
"<style> ul {margin-top:0px;} li {margin-left:50px;}</style>"
Note: it's adding margin-top to the UL but adding margin-left to the LI.
You can add that string before or after your HTML (but not mixed inside of the html elements as seen in the comments), it doesn't matter, but most people put styles at the top, before the HTML.
.HTMLbody = "<style> ul {margin-top:0px;} li {margin-left:50px;}</style> " _
& "Unbulleted Text" _
& "<br>" & "<br>" & "<b>Header</b>" _
& "<ul>" & "<li>" & "bullet one" _
& "</li>" & "<li>" & "bullet two" _
& "</li>" & "<li>" & "bullet three" _
& "</li>" & "</ul>" & "Unbulleted Text"
Upvotes: 2