What's wrong in this part of my code

Ramadan

Board Regular
Joined
Jan 20, 2024
Messages
227
Office Version
  1. 2021
Platform
  1. Windows
I have a long code to send email from excel and there are some texts that I need to change it's font to BOLD and the color to red
Through my searches online I have found a way to do that and thanks god it works even I'm not professional in VBA but still there are some issues I don't know how to fix them as you can see in the screenshot below ,

1- there are (" ") before and after the word and also there is one extra sign (") at the end before the email signature
2- (" Best Regards") is a part from my outlook signature but only this part is shown LEFT TO RIGHT while it should be right to left
3- how to put make the last red word before signature with underline like this ( :ملحوظة)

Here is the part of my code


VBA Code:
 newHTML = "<div dir='rtl' style='font-family:Calibri; font-size:11pt;'>" & _
              "<b>" & body1 & "</p>" & _
               "<p>" & body7 & "</p></b>" & _
              "<p>" & body2 & " <b>(" & membershipNo & ")</b> " & body3 & " <b>(" & _
              startDate & "</b>  -  <b> " & endDate & ")</b> ""<b>" & "<font color=red>" & period & "</font>" & "</b>"" </p>" & _
              "<p>" & body4 & "</p>" & _
             "<p>" & body5 & "</p>" & _
               "<b>" & "<font color=red>""<b>" & body6 & "</font>" & "</b>""</p></b>" & _
              "<\div>"""

[ATTACH type="full"]123765[/ATTACH]
 

Attachments

  • Untitled.png
    Untitled.png
    33.6 KB · Views: 7
There are a number of issues here with syntax, another issue is the method of attaching the file.

Make some adjustments based on the code below, it fixes the syntax issues and changes the method of attaching the file:
VBA Code:
    filePath = "C:\Users\bloggsj\Desktop\example.xlsm" ' Change this to your actual file path of attachment
    
    newHTML = "<div dir='rtl' style='font-family:Calibri; font-size:11pt;'>" & _
              "<b>" & body1 & "</b></p>" & _
              "<p>" & body7 & "</p>" & _
              "<p>" & body2 & " <b>(" & membershipNo & ")</b> " & body3 & _
              "<b>(" & StartDate & "</b> - <b> " & EndDate & ")</b> <b><font color='red'>" & Period & "</font></b></p>" & _
              "<p>" & body4 & "</p>" & _
              "<p>" & body5 & "</p>" & _
              "<p><b><font color='red'>" & body6 & "</font></b></p>" & _
              "</div>"
    
    With OutMail
        .BodyFormat = 2
        .Display
        .HTMLBody = newHTML
        ' Add the attachment
        .Attachments.Add filePath
        .To = ""
        .Subject = "Subject"
    End With
 
Upvote 0
Solution
There are a number of issues here with syntax, another issue is the method of attaching the file.

Make some adjustments based on the code below, it fixes the syntax issues and changes the method of attaching the file:
VBA Code:
    filePath = "C:\Users\bloggsj\Desktop\example.xlsm" ' Change this to your actual file path of attachment
   
    newHTML = "<div dir='rtl' style='font-family:Calibri; font-size:11pt;'>" & _
              "<b>" & body1 & "</b></p>" & _
              "<p>" & body7 & "</p>" & _
              "<p>" & body2 & " <b>(" & membershipNo & ")</b> " & body3 & _
              "<b>(" & StartDate & "</b> - <b> " & EndDate & ")</b> <b><font color='red'>" & Period & "</font></b></p>" & _
              "<p>" & body4 & "</p>" & _
              "<p>" & body5 & "</p>" & _
              "<p><b><font color='red'>" & body6 & "</font></b></p>" & _
              "</div>"
   
    With OutMail
        .BodyFormat = 2
        .Display
        .HTMLBody = newHTML
        ' Add the attachment
        .Attachments.Add filePath
        .To = ""
        .Subject = "Subject"
    End With
@Georgiboy Thank you so much it works now perfectly. and regarding ponit#2 left to right I found out that it was done by mistake in my outlook signature and fixed
Thank you so much for your help
 
Upvote 0

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