HTML email

Nichole09

Board Regular
Joined
Aug 27, 2016
Messages
132
Hello,

I have been searching the internet for sometime nowand cannot find solutions to my problems. I have the code below which generatesand email for me which works great! But I am just perhaps being picky about acouple items and hoping maybe someone can provide a solution to them?


I would likethe beginning of my paragraph to be intended. I have been trying to find somecode online that works like tab does but no luck. I tried <p> and I understandthis is used for starting a paragraph but it intends the entire email. I justwant a few spaces starting with “I am including….” I want to keep the HTMLformatting. Does anyone know of a solution for adding more spaces with HTML?
Second, mydefault signature is added but it creates extra spaces after the body of myemail down to the signature line. This is not being created from my defaultsignature, there are no additional spaces there. I understand when you add yoursignature to an outlook email there are already spaces added which one wouldnormally type through. Since the body is being added to the email there aremore spaces between the body and signature line then are needed. Anyway toremove spaces or additional lines?



Thank youkindly!!

Code:
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]Sub Email ()[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]   Dim OutApp As Object[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    Dim OutMail As Object[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    Dim strbody As String[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    Dim WS As Worksheet[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]  [/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    Set WS = Worksheets("Status")[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    [/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]Application.ScreenUpdating= False[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]Application.EnableEvents= False[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000] [/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    Set OutApp =CreateObject("Outlook.Application")[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    Set OutMail = OutApp.CreateItem(0)[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000] [/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    On Error Resume Next[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    With OutMail[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    .Display[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]        .To = WS.range("V5").value[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]        .CC = W.range("H16").value[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]        .BCC = ""[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]        .subject = "**Closing - "& WS.range("d4").value & " - " &WS.range("c13").value & " - " &WS.range("AB4").value & "**"[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]        .HTMLBody = "<pstyle='font-family:calibri;font-size:14.5'>" & _[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]        "Hi " &WS.range("ab9").value & "," &"<br></p>" & _[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]     "<pstyle='font-family:calibri;font-size:14.5'>" & "I am includingthe documents for this file as well as additional items that had beenrequested. Please email me directly with any questions you may have."& _[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]"</p>"& OutMail.HTMLBody[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]        .Display  [/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    End With[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    On Error GoTo 0[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][COLOR=#000000]
[/COLOR][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    Set OutMail = Nothing[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]    Set OutApp = Nothing[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000] [FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][COLOR=#000000]
[/COLOR][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/FONT]
[FONT=Calibri][COLOR=#000000]    Application.ScreenUpdating = True[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000]
[/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]Application.EnableEvents= True[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][COLOR=#000000][FONT=Times New Roman][SIZE=3][COLOR=#000000][FONT=Calibri][COLOR=#000000]
[/COLOR][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/FONT][/COLOR][/SIZE][/FONT]
[FONT=Calibri][COLOR=#000000]End Sub[/COLOR][/FONT]
[FONT=Times New Roman][SIZE=3][COLOR=#000000][/COLOR][/SIZE][/FONT]
[COLOR=#222222][FONT="Verdana"]



[/FONT][/COLOR]

 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
To do tabs in HTMl you can use the <pre> - I have added it to your code and by force of habit added an end </pre> - however I did test and if you don't need to have the closing value.
You could have also just add some spaces with the spacebar, but I think the html code works fine.

I have also highlighted that you have 2 .Display and only need 1

I tried adding my signature to this email and for me it actually adds it from where the cursor sits with no extra spaces for me at all so I don't know what to suggest to resolve your issue.

Code:
Sub Email()

Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim WS As Worksheet
Set WS = Worksheets("Status")
Application.ScreenUpdating = False
Application.EnableEvents = False

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next

    With OutMail


   [COLOR="#FF0000"] ''.Display <----- you dont need this as you have the display below as well[/COLOR]


        .To = WS.Range("V5").Value
        .CC = W.Range("H16").Value
        .BCC = ""
        .Subject = "**Closing - " & WS.Range("d4").Value & " - " & WS.Range("c13").Value & " - " & WS.Range("AB4").Value & "**"
        .HTMLBody = "<pstyle='font-family:calibri;font-size:14.5'>" & _
"Hi " & WS.Range("ab9").Value & "," & "<br></p>" & _
"<pstyle='font-family:calibri;font-size:14.5'>" & "[COLOR="#FF0000"][B]<pre>[/B][/COLOR]I am including the documents for this file as well as additional items that had beenrequested. Please email me directly with any questions you may have.[COLOR="#FF0000"][B]</pre>" [/B][/COLOR]& _
"</p>" & OutMail.HTMLBody

        .Display [COLOR="#FF0000"]'<-----heres the second one[/COLOR]

    End With

    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing
    Application.ScreenUpdating = True
    Application.EnableEvents = True

End Sub
 
Upvote 0
Thank you for your reply bugmonsta! I tried your suggestion and something about adding the "<pre>" overwrites my font style. It also does not add spaces as requested. I tried simply adding spaces but that only seems to work with .body not .HTMLbody Do you happen to have any other suggestions?
 
Upvote 0
Can you please post up your code with the <pre> in it and I will take that into Excel to see if it works for me/I can see what we can do to fix it
 
Upvote 0

Forum statistics

Threads
1,223,727
Messages
6,174,144
Members
452,547
Latest member
Schilling

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