Hello!
I am using VBA to send out emails containing a text body made up of bullet points with varying lengths (using the code from smozgur in this thread: Use VBA to enter a varying range of bullet points into body of email). Which creates a reference to the bullet list in the body text instead of typing the list references in the text directly (which makes it more difficult for me to format the list).
The code works perfectly however displays a margin between the bullet list and heading (list 1 in picture left) however i would like to remove the margin (list 2 in picture left). This can be done in outlook directly using the paragraph settings (picture right), would there be a way to change this formatting directly into the code below?
The code I'm using:
And the sheet layout:
Any thoughts/help would be greatly appreciated!
I am using VBA to send out emails containing a text body made up of bullet points with varying lengths (using the code from smozgur in this thread: Use VBA to enter a varying range of bullet points into body of email). Which creates a reference to the bullet list in the body text instead of typing the list references in the text directly (which makes it more difficult for me to format the list).
The code works perfectly however displays a margin between the bullet list and heading (list 1 in picture left) however i would like to remove the margin (list 2 in picture left). This can be done in outlook directly using the paragraph settings (picture right), would there be a way to change this formatting directly into the code below?
The code I'm using:
VBA Code:
Sub UL_list_margin_example()
'I am trying to set up an email containing two bullet lists where the number of bullets can vary
'Setting up outlook
Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")
'Variables setting
Dim StrBullet As String
Dim rng As Range
Dim cll As Range
Dim listItems As String
Dim listItems2 As String
Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)
'For the bulletitems
Set rng = Worksheets("Sheet1").Range("A3").CurrentRegion
For Each cll In rng.Cells
listItems = listItems & vbCrLf & "<li>" & cll.Value & "</li>"
Next cll
listItems = "<ul>" & vbCrLf & listItems & "</ul>"
Set rng = Worksheets("Sheet1").Range("A13").CurrentRegion
For Each cll In rng.Cells
listItems2 = listItems2 & vbCrLf & "<li>" & cll.Value & "</li>"
Next cll
listItems2 = "<ul>" & vbCrLf & listItems2 & "</ul>"
'main body text set up
StrBullet = "<BODY style=font-size:11pt;font-family:""Calibri Light"">" & _
Worksheets("Sheet1").Range("C1") & "<br><br>" & _
"<b>" & Worksheets("Sheet1").Range("A1") & "</b>" & _
vbCrLf & _
listItems & _
"<b>" & Worksheets("Sheet1").Range("A11") & "</b>" & _
vbCrLf & _
listItems2 & _
"<b>" & Worksheets("Sheet1").Range("C2") & "</b>"
'generate email
With olMail
.To = Worksheets("Sheet1").Range("D1")
.CC = Worksheets("Sheet1").Range("D2")
.Subject = Worksheets("Sheet1").Range("D3")
.HTMLBody = StrBullet
.Display
End With
End Sub
And the sheet layout:
Any thoughts/help would be greatly appreciated!