Email Me. to label and text on two lines issues

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hi good evening. hope you can help me please, i have the code below which isnt working at all i have rearranged it so the layout on the email is different, but as i have been moving all the label.caption together on one row and then the TextBox.text or value on another row it doesnt work, the whole lot of code is highlighted in red. Also on some lines it wont let me put the '_' after the '&', please can you help me

VBA Code:
Private Sub CommandButton2_Click()

    If ComboBox2.Value = "" Then
        MsgBox "Please enter 'Allocated To EOD'"
        Exit Sub
    Else

    End If
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
    
    Set aOutlook = CreateObject("Outlook.Application")
    Set aEmail = aOutlook.CreateItem(0)

    ulFlags = ulFlags Or &H1 ' SECFLAG_ENCRYPTED
    
    aEmail.PropertyAccessor.SetProperty PR_SECURITY_FLAGS, (ulFlags)

          aEmail.HTMLBody = "<html><body>" & _
                            "<p>Hi " & Me.TextBox14.Value & "</p>" & _
                            "<table border=""1"", cellpadding=""10"", style=background:""0xFFFFFF"" >" & _
                "<tr>" & _
                "<th>Details:</th>" & _
                "<tr>" & _
                            "<td>" & Me.Label12.Caption & "</td>" & _
                            "<td>" & Me.Label7.Caption & "</td>" & _
                            "<td>" & Me.Label13.Caption & "</td>" & _
                            "<td>" & Me.Label14.Caption & "</td>" & _
                            "<td>" & Me.Label6.Caption & "</td>" & _
                            "<td>" & Me.Label1.Caption & "</td>" & _
                            "<td>" & Me.Label2.Caption & "</td>" & _
                            "<td>" & Me.Label3.Caption & "</td>" & _
                            "<td>" & Me.Label4.Caption & "</td>" & _
                            "<tr>" &
                            "<td>" & Me.TextBox1.Text & "</td>" & _
                            "<td>" & Me.TextBox2.Value & "</td>" & _
                            "<td>" & Me.TextBox3.Text & "</td>" & _
                            "<td>" & Me.TextBox4.Value & "</td>" & _
                            "<td>" & Me.TextBox5.Text & "</td>" & _
                            "<td>" & Me.TextBox6.Value & "</td>" & _
                            "<td>" & Me.TextBox7.Value & "</td>" & _
                            "<td>" & Me.TextBox8.Value & "</td>" & _
                            "<td>" & Me.TextBox9.Value & "</td>" & _
                            "</table>"  &_
                "<br><br><br><br><br><br>" & _
                "<p>Many Thanks</p>" & _
                "<p>Complex Team</p>" & _
                "</body></html>"


        aEmail.Recipients.Add (UserForm6.TextBox13.Value)
        aEmail.CC = ""
        aEmail.BCC = ""
        aEmail.Subject = (UserForm1.Label10.Caption) & (UserForm1.TextBox8.Value)
        aEmail.Display

Unload Me

End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I have never seen line continuation done like that and suspect that is at least one issue you have. Should be more like
VBA Code:
          aEmail.HTMLBody = "<html><body>" _
                            & "<p>Hi " & Me.TextBox14.Value & "</p>" _
                           & "<table border=""1"", cellpadding=""10"", style=background:""0xFFFFFF"" >"
etc. I don't use line continuation much, preferring this method
VBA Code:
strBody =  "<html><body><p>Hi " & Me.TextBox14.Value & "</p>"
strBody = strBody & "<table border=""1"", cellpadding=""10"", style=background:""0xFFFFFF"" >"
strBody = strBody & ...
aEmail.HTMLBody = strBody
N.B. in cases where spaces are required between portions, best to put them at the beginning of the line so that they're easily evaluated for consistency.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

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