add borders to HTML email

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
703
Office Version
  1. 2016
Platform
  1. Windows
I can't figure out how to add the inside borders to a table.

VBA Code:
    .HTMLBody = "<html><head><title></title></head><body>" _
        & "<style> table {border:2px black solid !important} </style><table style=""width:600px""><tr>" _
        & "<p><center><span style=""font-size:19px;"">" _
        & "<br></span></center><br>" _
        & "<span style=""font-size:15px;"">" _
        & "" _
        & "<center><table style=""width:590px;""><tbody style=""font-size:13px;"">" _
        & "<tr align=""center"";style=""color:#c00000;""><td></td><td></td><td></td><td></td></tr>" _
        & "<tr><td></td><td></td><td></td><td align=""center""></td></tr>" _
        & "<tr><td></td><td></td><td></td><td align=""center""></td></tr>" _
        & "<tr><td></td><td></td><td></td><td align=""center""></td></tr>" _
        & "<tr><td></td><td></td><td></td><td align=""center""></td></tr>" _
        & "</table></center></table>" & .HTMLBody

I have a table nested inside of another table. It's the nested table that I'm would like to add borders to.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

6StringJazzer

Well-known Member
Joined
Jan 27, 2010
Messages
2,701
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Try this change:

Rich (BB code):
& "<center><table style=""width:590px; border: 1px solid black;""><tbody style=""font-size:13px;"">" _
 
Upvote 0

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
703
Office Version
  1. 2016
Platform
  1. Windows
Try this change:

Rich (BB code):
& "<center><table style=""width:590px; border: 1px solid black;""><tbody style=""font-size:13px;"">" _
Added that bit started a border, but it isn't a grid with a solid line like I was looking for.
1638843504826.png

VBA Code:
    test1 = "<html><head><title></title></head><body>" _
        & "<style> table.main {border:2px solid black} </style><table class=main style=""width:600px""><tr>" _
        & "<p><center><span style=""font-size:19px;"">" _
        & "<br></span></center><br>" _
        & "<span style=""font-size:15px;"">" _
        & "" _
        & "<center><table class=""schedule"" style=""width:590px;border: 1px solid black;""><tbody style=""font-size:13px;"">" _
        & "<tr align=""center"";style=""color:#c00000;""><td></td><td></td><td></td><td></td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "</table></center></table>" & .HTMLBody
 
Upvote 0

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
703
Office Version
  1. 2016
Platform
  1. Windows
I figured it out. I had to use CCS.
1638888527050.png

VBA Code:
    test1 = "<html><head><title></title></head><body>" _
        & "<style> table.main {border:2px solid black} </style>" _
        & "<style> table.schedule {border-collapse:collapse;border:1px solid black;}" _
        & "<style> table.schedule td {border-collapse:collapse;border:1px solid black;}" _
        & "<table class=main style=""width:600px""><tr>" _
        & "<center><span style=""font-size:19px;"">" _
        & "TITLE<br></span></center><br>" _
        & "<span style=""font-size:15px;"">" _
        & "Text" _
        & "<center><table class=""schedule"" style=""width:590px;""><tbody style=""font-size:13px;"">" _
        & "<tr align=""center"";style=""color:#c00000;"">" _
        & "<td>header</td><td>header</td><td>header</td><td>header</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "</tbody></table></center>" _
        & "Text</table></body></html>" & .HTMLBody
 
Upvote 0
Solution

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
703
Office Version
  1. 2016
Platform
  1. Windows
Here is the complete code:

VBA Code:
Sub Mail_test()
   
    Dim OutApp As Object
    Dim OutMail As Object

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
   
    With OutMail
   
    test1 = "<html><head><title></title></head><body>" _
        & "<style> table.main {border:2px solid black} </style>" _
        & "<style> table.schedule {border-collapse:collapse;border:1px solid black;}" _
        & "<style> table.schedule td {border-collapse:collapse;border:1px solid black;}" _
        & "<table class=main style=""width:600px""><tr>" _
        & "<center><span style=""font-size:19px;"">" _
        & "TITLE<br></span></center><br>" _
        & "<span style=""font-size:15px;"">" _
        & "Text" _
        & "<center><table class=""schedule"" style=""width:590px;""><tbody style=""font-size:13px;"">" _
        & "<tr align=""center"";style=""color:#c00000;"">" _
        & "<td>header</td><td>header</td><td>header</td><td>header</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "<tr><td>text</td><td>text</td><td>text</td><td align=""center"">text</td></tr>" _
        & "</tbody></table></center>" _
        & "Text</table></body></html>" & .HTMLBody
   
    .Display
       
    .HTMLBody = test1
   
    End With
       
    Set OutMail = Nothing
    Set OutApp = Nothing

End Sub
 
Upvote 0

Forum statistics

Threads
1,191,120
Messages
5,984,762
Members
439,909
Latest member
daigoku

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top