I've tried several ways including making another string that acts as a space, and also " ".
StrBody2 = "<b>Downtime particulars</b>" & "<br>" & _
"Short description: " & space(10) & _
Range("External_Start_Description").Text & "<br>" & "<br>"
I want a space between "Short description" and Range("External_Start_Description").Text.
I expect this has to do with using the range function in the string.
Context: this string is later used in an email with other strings:
.HTMLBody = "<p><font color=""#112369"" face=""arial"" size=""10px"">" & StrBody & StrBody2 & RangetoHTML(rng) & StrBody3
HTML collapses runs of multiple spaces to a single space - you need to use the non-breaking space entity if you want a run of spaces.
Replace(space(10), " ", " ")
All you need to do is put quotes with a space in your concatenation like below:
StrBody2 = "<b>Downtime particulars</b>" & "<br>" & _
"Short description: " & " " & Range("External_Start_Description").Text & "<br>" & "<br>"
Related
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>"
I am getting the above error whilst running this commmand:
CurrentDb.Execute "UPDATE VolunteerDetails " & _
" SET FirstName=" & Me.frst_Name_txt & _
", LastName='" & Me.lst_Name_txt & "'" & _
", PostalCode='" & Me.pst_Code_txt & "'" & _
" WHERE VolsID=" & Me.vol_ID_txt
Can anyone explain why?
Thanks!
I think your problem is in the FirstName value. It seems to be a string and so you need to put your value inside single quotes
CurrentDb.Execute "UPDATE VolunteerDetails " & _
" SET FirstName='" & Me.frst_Name_txt & "'" & _
", LastName='" & Me.lst_Name_txt & "'" & _
", PostalCode='" & Me.pst_Code_txt & "'" & _
" WHERE VolsID=" & Me.vol_ID_txt
Said that, please read about Sql Injection and Parameterized queries. Your code, as is, it is very weak and could fail simply if someone types a LastName like O'Malley (the single quote breaks your string concatenation)
As pointed by a comment above, I suppose that these variables are not TextBoxes but just string variables. If these are TextBoxes then, the value to set the field to comes from the Text property of the TextBox. Something like
" SET FirstName='" & Me.frst_Name_txt.Text & "'"