I would like to send a complex Email using VBA and HTLM, but I cant achieve this.
I am used to sending simple Email, with some links and some variables, but what I need to do here is more complex.
I need to send an Email that looks like the one in this tutorial, but cant manage to deal with the HTML and HMTLbody.
https://webdesign.tutsplus.com/articles/build-an-html-email-template-from-scratch--webdesign-12770
I've been researching, but cant find a way to properly code it.
Usually, my code looks something like this :
.HTMLBody = "Bonjour, les résultas d'essais sur :" & "<br>" & "<br>" & "<b>" & "Produit : " & "</b>" & produit & "<br>" & "<b>" & "Projet : " & "</b>" & codeproj & "<br>" & "<b>" & "Formule : " & "</b>" & formule & "<br>" & "<br>" & "sont disponibles !" & "<br>" & "Ceux-ci se trouvent dans le répertoire suivant : " & "<a href=""" & Chemin & lien & """>Lien</a > " & "<br>" & "<br>" & "Merci."
What I need is just some help to get started and the rest should be fine.
Thank you very much!
Related
picture probleme breakline
, I have a problem with my breakline not working properly in my either caculated fields or my expression.
I would like to split by created date and title etc...
do you know why it is not working ?
= "<b>"+ "Created on: " + "</b>" & CDate(Fields!ticket_ticketSolutions_date_create.Value).ToString("dd/MM/yy HH:mm")
& Environment.NewLine & Environment.NewLine &
"<b>" + "Approval date: " + "</b>" & iif(IsNothing(Fields!date_approval.value),"Not Approved",CDate( Fields!date_approval.Value).ToString("dd/MM/yy HH:mm"))
& Environment.NewLine &
Environment.NewLine &
"<b>" + "Solutions: " +"</b>" & Fields!ticket_ticketSolutions_content_plainText.Value
=Join( LookupSet(Fields!ticket_tickets_sourceId.value, Fields!itemId.value, Fields!start_end_solution_data.value, "Ticket_ticket_ticket_Solutions"), vbcrlf)
calculated fields ,
expression
It looks like you are using HTML tags in your text box. When using HTML, line breaks do not work.
Replace the NewLine with the HTML break tag <br>.
= "<b>"+ "Created on: " + "</b>" & CDate(Fields!ticket_ticketSolutions_date_create.Value).ToString("dd/MM/yy HH:mm") &
"<br><br>" & "<b>" + "Approval date: " + "</b>" &
IIF(IsNothing(Fields!date_approval.value), "Not Approved", CDate( Fields!date_approval.Value).ToString("dd/MM/yy HH:mm")) &
"<br>" & "<br>" & "<b>" + "Solutions: " +"</b>" & Fields!ticket_ticketSolutions_content_plainText.Value
I have a VBA object, aPosition.
I am trying to display information aPosition.something in an email.
My code gives me a syntax error.
strBody = "<HTML>" strBody & "<BR> & <p style='font-family:Trebuchet MS,sans-serif;font-size:22'>Equity position in sell: " & aPosition.SEC_NAME & " (" & aPosition.ISIN & ")" & " now in "& aPosition._RANKING" </p> & _
" Target Price: " & aPosition.TARGET_PRICE & "<BR>" & _
"<b><span style=""color:#C00000"">We have downgraded</span style=""color:#C00000""></b>" & aPosition.SEC_NAME & "<BR>" & " <U>Clients Impacted:</U><BR>"
You have a few problems when building your string.
First of all, you can use single quotes in your styles to eliminate the possible double-double quotes confusion.
Secondly, you seem to have strBody mixed in there twice for some reason.
Also, whatever aPosition is, you cannot have a property that starts with an underscore (aPosition._Ranking not valid), so I removed just that underscore. (so double check that part)
Try it like this:
strBody = "<HTML>" & strBody & "<BR><p style='font-family:Trebuchet MS,sans-serif;font-size:22'>Equity position in sell: " & aPosition.SEC_NAME & " (" & aPosition.ISIN & ") now in " & aPosition.RANKING & "</p>" & _
" Target Price: " & aPosition.TARGET_PRICE & "<BR>" & _
"<b><span style='color:#C00000'>We have downgraded</span style='color:#C00000'></b>" & aPosition.SEC_NAME & "<BR><U>Clients Impacted:</U><BR>"
The rule of thumb is to make sure you set a well-formed HTML markup to the HTMLBody property, for example, I see the following:
strBody = "<HTML>" strBody & "<BR>
If you want to modify the existing email body you need to paste your HTML pieces after the <body> tag and before the closing </body> tag.
I'm adding an expression on VS 2017 above my report to display the name and some fields but also to display a second row with a different color and size. The font color works perfectly but for a reason the font size is the same on both rows (even when I put different size). Below is my code
="<font color='#4169e1' size='14pt'>" & "Platform by Account # " & Parameters!AccountID.Value & " " & "</font>" & "<br>" &
"<font color='red' size='2pt'>" & "Report generated on: " & Now() & "</br> </font>"
Any suggestion to fix the issue?
You just need to remove the 'pt'
="<font color='#4169e1' size='14'>" & "Platform by Account # " & Parameters!AccountID.Value & " " & "</font>" & "<br>" &
"<font color='red' size='2'>" & "Report generated on: " & Now() & "</br> </font>"
I'm working on a VBA code in Excel to get input from reports and send emails.
I'm trying to avoid line breaks in my email body.
With olMail
.To = rep
.Subject = title & " - " & EndTitle
'.Recipients.Add rep
.Attachments.Add filePath & "\" & title & " - " & EndTitle & ".pdf"
.htmlBody = "<BODY style=font-size:12pt;font-family:Arial><b><u>Here is an email</u></b></BODY>" & "<BODY style=font-size:12pt;font-family:Arial><b><u>Here is an email</u></b></BODY>" _
& "<br>" & "<b>HK</b>" & "<b>" & amt & "</b>" _
& "<br>" & "Value date" & "<b>" & Trans & "</b>" & "<br>" &
initial
.Display
'.Send
End With
My email looked like this
Here is the email
Here is the email
What I want the email body to look like
Here is the email Here is the email
(on the same line)
Use this instead:
.htmlBody = "<BODY style=font-size:12pt;font-family:Arial><b><u>Here is an emailHere is an email</u></b>" _
& "<br>" & "<b>HK" & amt & "</b>" _
& "<br>" & "Value date" & "<b>" & Trans & "</b>" & "<br>" & initial & "</BODY>"
Or this, depending on which line breaks you want gone:
.htmlBody = "<BODY style=font-size:12pt;font-family:Arial><b><u>Here is an emailHere is an email</u></b>" _
& "<b>HK" & amt & "</b>" _
& "Value date" & "<b>" & Trans & "</b>" & initial & "</BODY>"
See how I encapsulated all the HTML between the opening and closing BODY tags?
I am having trouble with applying Bold on a part of a sentence for an automatically generated email.
In my VBA script:
Public strBody As String
.HtmlBody = strBody
Dim FormulaCell As Range
Dim FormulaRange As Range
For Each FormulaCell In FormulaRange.Cells
With FormulaCell
I am able to Bold a whole sentence using "< b >" & "**Text Here**" & "< /b >" &
But it seems impossible to apply the same logic to a more complex sentence, or a referenced value.
strBody = "Hello, " & vbNewLine & vbNewLine & _
"Your task : " & Cells(FormulaCell.Row, "B").Value & " with the mention: " & Cells(FormulaCell.Row, "C").Value & " is nearing its Due Date: "
What I would like to Bold in the above sentence is the value of the FormulaCells.
strBody = "Hello, " & vbNewLine & vbNewLine & _
"Your task : " & **Cells(FormulaCell.Row, "B").Value** & " with the mention: " & **Cells(FormulaCell.Row, "C")**.Value & " is nearing its Due Date: "
So it would look something like that in my email:
Hello
Your task : Eat Potatoes with the mention: Potatoes are Delicious is nearing its Due Date:
Is this something that can be done?
edited
strBody = "<p>Hello</p>, " & vbNewLine & vbNewLine & _
"<p>Your task : <b>" & Cells(FormulaCell.Row, "B").Value & _
"</b> with the mention: <b>" & Cells(FormulaCell.Row, "C").Value & _
"</b> is nearing its Due Date: </p>"