add borders to HTML email

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
564
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

6StringJazzer

Well-known Member
Joined
Jan 27, 2010
Messages
1,639
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;"">" _
 

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
564
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
 

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
564
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
 
Solution

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
564
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,043
Messages
5,835,099
Members
430,341
Latest member
kelstnmate

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