Email error on border code

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hello good afternoon, hope you can help me please? i have the code below but it is all in red, i am trying to put a border around the email data that is copied over from a sheet called 'Raised', hope you can help please.
VBA Code:
Private Sub CommandButton3_Click()
Const PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003"
Dim aOutlook As Object
Dim aEmail As Object
Dim ulFlags As Integer
Dim rngeAddresses As Range, rngeCell As Range, strRecipients As String
Dim rngDataToEmail As Range

    Set aOutlook = CreateObject("Outlook.Application")
    Set aEmail = aOutlook.CreateItem(0)


 ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED

    aEmail.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, (ulFlags)

    With Sheets("Raised")
        Set rngDataToEmail = .Range("B1:Q" & .Range("B" & Rows.Count).End(xlUp).Row)
    End With


    
aEmail.HTMLBody = "<html><body><p>Hi " & Me.TextBox9.Value & "</p>" _
                    "<table border=""1"", cellpadding=""10"", style=background:""0xFFFFFF"" >" & _
                    "<td>" & Me.ComboBox2.Value & "</td>" & _
                    "<td>" & RangetoHTML(rngDataToEmail) & "</td>" & _
                    "<td>" & Any issues let your FTL know ASAP"</td>" & _
                    "<td>" & "<p>Many Thanks & "</td>" & __
                    "<td>" & "<p>Complex Team & "</td>" & _
                    "<td>" & "</body></html>"
                    "</tr>" & _
                    "</table>" & _
                "<br><br><br><br><br><br>" & _
                "<p>Any issues, please contact your FTL.</p>" & _
                "<p>Many Thanks</p>" & _
                "<p>Complex Team</p>" & _
                "</body></html>"

    aEmail.Recipients.Add (UserForm8.TextBox21.Value)
    aEmail.CC = ""
    aEmail.BCC = ""
    aEmail.Subject = (UserForm1.TextBox8.Value)
    aEmail.Display

    Unload Me
Dim Cll As Range
    Dim sh As Worksheet, f As Range
    Set sh = Sheets("Raised")
    Set f = sh.Range("B2:B1000").Find(ComboBox2.Value, , xlValues, xlWhole)
    If Not f Is Nothing Then
        sh.Select
        f.Select
    Else
        MsgBox "Does not exist"
    End If
    For Each Cll In sh.Range("B2:B1000")
        If Cll.Value = f Then
            Cll.Interior.Color = vbGreen
        End If
        Next Cll
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
The code below is the section that is highlighted in red, any help is gratefully appreciated.
VBA Code:
aEmail.HTMLBody = "<html><body><p>Hi " & Me.TextBox9.Value & "</p>" _
                    "<table border=""1"", cellpadding=""10"", style=background:""0xFFFFFF"" >" & _
                    "<td>" & Me.ComboBox2.Value & "</td>" & _
                    "<td>" & RangetoHTML(rngDataToEmail) & "</td>" & _
                    "<td>" & Any issues let your FTL know ASAP"</td>" & _
                    "<td>" & "<p>Many Thanks & "</td>" & __
                    "<td>" & "<p>Complex Team & "</td>" & _
                    "<td>" & "</body></html>"
                    "</tr>" & _
                    "</table>" & _
                "<br><br><br><br><br><br>" & _
                "<p>Any issues, please contact your FTL.</p>" & _
                "<p>Many Thanks</p>" & _
                "<p>Complex Team</p>" & _
                "</body></html>"
 
Upvote 0
Try it as below:
VBA Code:
aEmail.HTMLBody = "<html><body><p>Hi " & Me.TextBox9.Value & "</p>" & _
                    "<table border=""1"", cellpadding=""10"", style=background:""0xFFFFFF"" >" & _
                    "<td>" & Me.ComboBox2.Value & "</td>" & _
                    "<td>" & RangetoHTML(rngDataToEmail) & "</td>" & _
                    "<td>Any issues let your FTL know ASAP</td>" & _
                    "<td><p>Many Thanks</td>" & _
                    "<td><p>Complex Team</td>" & _
                    "<td></body></html>" & _
                    "</tr>" & _
                    "</table>" & _
                    "<br><br><br><br><br><br>" & _
                    "<p>Any issues, please contact your FTL.</p>" & _
                    "<p>Many Thanks</p>" & _
                    "<p>Complex Team</p>" & _
                    "</body></html>"
 
Upvote 0
Try it as below:
VBA Code:
aEmail.HTMLBody = "<html><body><p>Hi " & Me.TextBox9.Value & "</p>" & _
                    "<table border=""1"", cellpadding=""10"", style=background:""0xFFFFFF"" >" & _
                    "<td>" & Me.ComboBox2.Value & "</td>" & _
                    "<td>" & RangetoHTML(rngDataToEmail) & "</td>" & _
                    "<td>Any issues let your FTL know ASAP</td>" & _
                    "<td><p>Many Thanks</td>" & _
                    "<td><p>Complex Team</td>" & _
                    "<td></body></html>" & _
                    "</tr>" & _
                    "</table>" & _
                    "<br><br><br><br><br><br>" & _
                    "<p>Any issues, please contact your FTL.</p>" & _
                    "<p>Many Thanks</p>" & _
                    "<p>Complex Team</p>" & _
                    "</body></html>"
Hi thank you for the code, i have amended to the above but the borders arent in line for some reason, hope you can still help please? I have attached a screenshot. I also get an error on the code below where it is highlighted in yellow.
VBA Code:
If Cll.Value = f Then
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    200.8 KB · Views: 9
Upvote 0
Should it look more like this:
VBA Code:
    aEmail.HTMLBody = "<html><body><p>Hi " & Me.TextBox9.Value & "</p>" & _
                        "<table border=""1"", cellpadding=""10"", style=background:""0xFFFFFF"" >" & _
                        "<td>" & Me.ComboBox2.Value & "</td>" & _
                        "<td>" & RangetoHTML(rngDataToEmail) & "</td>" & _
                        "</table>" & _
                        "<br><br><br>" & _
                        "<td>Any issues let your FTL know ASAP</td>" & _
                        "<td><p>Many Thanks</td>" & _
                        "<td><p>Complex Team</td>" & _
                        "<td></body></html>"
 
Upvote 0
Solution
Should it look more like this:
VBA Code:
    aEmail.HTMLBody = "<html><body><p>Hi " & Me.TextBox9.Value & "</p>" & _
                        "<table border=""1"", cellpadding=""10"", style=background:""0xFFFFFF"" >" & _
                        "<td>" & Me.ComboBox2.Value & "</td>" & _
                        "<td>" & RangetoHTML(rngDataToEmail) & "</td>" & _
                        "</table>" & _
                        "<br><br><br>" & _
                        "<td>Any issues let your FTL know ASAP</td>" & _
                        "<td><p>Many Thanks</td>" & _
                        "<td><p>Complex Team</td>" & _
                        "<td></body></html>"
Thank you for your help
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

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
Back
Top