What I'm trying to do is to copy a range from Excel (2 columns) and to paste in into email body in Outlook. I'd like to get also 2 columns in email body but I still receive everything in one line. Here's my code:
Tresc = "Cześć" & vbCr & vbCr & " słówko/a na dzisiaj to:" & vbCr & vbCr & Tresc & vbNewLine
'utworzenie hiperłącza
Hiperlacze = "mailto:" & Trim(LCase(Adres)) & _
"?subject=" & Tytul & _
"&body=" & Tresc
I believe you are looking for the vbCRLF built-in for "carriage return/linefeed" instead of just vbCR.
Since this is a mailto-link, there are some other rules in play. Replace the vbCr with "%0D%0A".
Example:
Tresc = "Cześć%0D%0Asłówko/a na dzisiaj to:" 'etc.
Related
I am generating an email that shows trades for the day in the body of an email. Currently the only way I can do this is with an If then statement for specific numbers of trades. If we traded 10, I need an if then statement with 10 as the variable criteria, but if I only have 9, then I get an error. I want a dynamic method instead. I can do a For Loop that will list all the trades in debug.print, but in the email, it each trade overwrites the prior trade and I show only one line. I also need an intro like "Hi, today today's trades are: " followed by each trade listed below line by line.
I tried this and it works but only if I have the right number of trades and a variable that matches it. For example, if I had 23 trades, I need an If statement with 23 as a variable value in this case m. I used Arrays as VBA does not let me create a list. Unfortunately, I cannot pull the whole array, I need to pull line by line. If I could pull the array, I could just have a simple loop.
If m = 23 Then
.Body = "Hi Chris," & vbLf & vbLf & "The following trade(s) was completed today:" & vbLf & vbLf & ArrayValues(0) & vbLf & ArrayValues(1) & vbLf & ArrayValues(2) & vbLf & ArrayValues(3) & vbLf & ArrayValues(4) & vbLf & ArrayValues(5) & vbLf & ArrayValues(6) & vbLf & ArrayValues(7) & vbLf & ArrayValues(8) & vbLf & ArrayValues(9) & vbLf & ArrayValues(10) & vbLf & ArrayValues(11) & vbLf & ArrayValues(12) & vbLf & ArrayValues(13) & vbLf & ArrayValues(14) & vbLf & ArrayValues(15) & vbLf & ArrayValues(16) & vbLf & ArrayValues(17) & vbLf & ArrayValues(18) & vbLf & ArrayValues(19) & vbLf & ArrayValues(20) & vbLf & ArrayValues(21) & vbLf & ArrayValues(22) & vbLf & vbLf & "Thanks"
End if
I want to use something like:
For b = 1 To LastRow
If Trades.Range("H" & b) = TDate Then
Debug.Print (Range("B" & b) & " " & Range("C" & b) & " " & Range("D" & b) & " " & Range("F" & b) & " " & Range("G" & b))
End If
Next b
This way it does not matter how may trades I have, one formula would over it all. Each Range has a trade characteristic.
If I do a debug.Print in the immediate window I get a list just like I want, but in the email, each line overwrites the prior trade.
I am a rookie at this and appreciate any help. Thanks
Sounds like you need to build a string which can be assigned to the message body. For such tasks you can use String Functions available in VBA where you can prepare the correct string and then assign to the message body.
If m = 23 Then
.Body = "Hi Chris," & vbLf & vbLf & "The following trade(s) was completed today:" & vbLf & vbLf & ArrayValues(0) & vbLf & ArrayValues(1) & vbLf & ArrayValues(2) & vbLf & ArrayValues(3) & vbLf & ArrayValues(4) & vbLf & ArrayValues(5) & vbLf & ArrayValues(6) & vbLf & ArrayValues(7) & vbLf & ArrayValues(8) & vbLf & ArrayValues(9) & vbLf & ArrayValues(10) & vbLf & ArrayValues(11) & vbLf & ArrayValues(12) & vbLf & ArrayValues(13) & vbLf & ArrayValues(14) & vbLf & ArrayValues(15) & vbLf & ArrayValues(16) & vbLf & ArrayValues(17) & vbLf & ArrayValues(18) & vbLf & ArrayValues(19) & vbLf & ArrayValues(20) & vbLf & ArrayValues(21) & vbLf & ArrayValues(22) & vbLf & vbLf & "Thanks"
End if
Your strategical mistake is that you are trying to set up the Body property for a specific case. Instead, consider concatenating the string with the required piece of data (another string) which makes sense for a particular case. And only when you are done adding all the bits to the result string, you can assign it to the message body.
Be aware, the Body property is a plain text string and doesn't deliver any formatting. Instead, I'd suggest using the HTMLBody property instead. The HTMLBody property should be an HTML syntax string. Setting the HTMLBody property will always update the Body property immediately.
I want to add space before the Chr(149) to make the email look more visually pleasing. Could you guys help me?
My current VBA code is the following:
Sub EmailHyperlink()
'updated by Extendoffice 20190815
Dim xOtl As Object
Dim xOtlMail As Object
Dim xStrBody As String
xStrBody = "Hi [Name]" & "<br>" _
& " " & "<br>" _
& "we receives monthly traffic of 4,000 visitors looking for video services, and we can help [Agency Name] get more qualified inquiries." & "<br>" _
& " " & "<br>" _
& "We created a USD -worth of promotion package available for USD only until August 17, 2022, which includes placements in:" & "<br>" _
& " " & "<br>" _
& Chr(149) & "Featured Video Design - visitors, avg. session time." & "<br>" _
& Chr(149) & " Top Video Production Companies - visitors, avg. session time." & "<br>" _
& Chr(149) & " Top Video Marketing Agencies - visitors, avg. session time." & "<br>" _
& Chr(149) & " 10 Best Video Commercials - visitors, avg. session time." & "<br>" _
& " " & "<br>" _
& "Slots are limited and secured on a first-come, first-served basis." & "<br>" _
& "<br>" _
& "If interested, kindly reply to this email or book a meeting with me." & "<br>" _
& " " & "<br>" _
& " " & "<br>" _
& "Thank you."
On Error Resume Next
Set xOtl = CreateObject("Outlook.Application")
Set xOtlMail = xOtl.CreateItem(olMailItem)
With xOtlMail
.To = "Email Address"
.CC = " "
.Subject = "Would [Agency Name] want more exposure for its video services? "
.HTMLBody = .HTMLBody & xStrBody
.Display
End With
Set xOtl = Nothing
Set xOtlMail = Nothing
End Sub
i see you use <A HREF...>, suppose you could use unordered list with the <ul>-tag.
Here's an example from w3schools HTML Lists:
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Coffee
Tea
Milk
Do you mean vertical space or horizontal?
For vertical space, instead of using <br> it is easier to control spacing using <p>. So you might use <p style="margin:1em 0;">, or instead of 1em, 20px.
For horizontal space, you can add a bit more spacing by using a non-breaking space. So that will look like this: " ". That is, space, non-breaking space, space: and this will achieve three spaces. (Multiple spaces without the non-breaking space obviously only achieve one space.)
I am creating some emails through vba in excel. Currently using the html method for the email body and adding the mail body text by combining values of different cells in a worksheet. I clearly marked the font as Calibri 11 and it is creating the mails with the required font but some users get the mail with different font in email body.
Also, the recipients who are facing this problem have the "Dear" part and "Thank you " part showing as Calibri 11 but the rest of the content in Times New Roman 12. Can someone please help me with this issue.
The code for email body is like this:
.htmlbody = "<body style = 'font-size:11pt; font-family:Calibri; color:RGB(0,0,0);'>" & y & vbNewLine & _
"<p>" & varPart1 & varPart2 & "<sup>" & varPart3 & "</sup>" & varPart4 & varPart5 & "<sup>" & _
varPart6 & "</sup>" & varPart7 & "</p>" & _
"<p>" & varPart8 & "</p>" & _
"<p><span>" & varPart9 & "</span></p>" & _
"<span>" & varPart10 & "</body>"
I have a workbook with an userform that captures user input into string and single variables and I want to display a text consisting those variables into a text box on the same userform using new line and tab.
Example:
Dim dog as String 'rex
Dim years as Single '5
Dim owner As String 'Joe
Dim address as String '123 Sample Street
Dim value as Single '300.00
I would like to have a textbox on my form, that would display:
The dog's name is rex. He is 5 years old.
Owner: Joe
Address: 123 Sample Street
Treatment value: 300.00
I used
textbox.value = "The dog's name is " & dog & vbNewLine & vbNewLine & "Owner: " & owner & vbNewLine & "Address: " & address & vbNewLine & vbNewLine & "Treatment value: " & value
But after some time i will not be able to add another character to this line and I have plenty more variables mixed with text to come.
Can you suggest how this can be done?
Update: Resolved
Many thanks for your help.
Try
textbox.value = "The dog's name is " & dog & vbNewLine & vbNewLine
textbox.value = textbox.value & "Owner: " & owner & vbNewLine
textbox.value = textbox.value & "Treatment value: " & value & vbNewLine
Continue with other fields!
Try like this:
textbox.value = "The dog's name is " & dog & vbNewLine & vbNewLine & _
"Owner: " & owner & vbNewLine & _
"Address: " & address & vbNewLine & vbNewLine _
& "Treatment value: " & value
The " _" signs help you break the code into more lines. Note, that we have 2 signs - space and underscore there.
A small info - it is possibly good to consider passing the text as a .Text and not as .Value. Here is something good to read - Distinction between using .text and .value in VBA Access
I am using vba in outlook to generate an email. I would like to find a way to move some text over to the right, about 100 pixels.
since I don't believe there is a way to incorporate css or styles in vba I am looking for a way to add more than one space to get the text moved over. however when I try space() function and " ", even if I repeat these codes a number of times it only ever gives me one space.
can someone please help me and show me what I need to do, thanks
"<br><br><br>" & "3PL & HAULAGE SUPPLIERS: " & " " & "<font size=""4.5"" face=""calibri"" color=""red"">" & "<b>" & EmailCount & "</b></font>" & vbNewLine & _
This will add 10 white spaces just before 3PL. You may need to adjust as the pixel distance will be relative to the font
TRIED AND TESTED
Sub test()
Dim WS As String
WS = " "
For i = 1 To 10
WS = WS & " "
Next i
Debug.Print "<br><br><br>" & WS & "3PL & HAULAGE SUPPLIERS: " & " " & "<font size=""4.5"" face=""calibri"" color=""red"">" & "<b>" & EmailCount & "</b></font>" & vbNewLine
End Sub