Hello, this is my first post so I apologize if i make any mistakes
I have the following code that emails the status of a workbook so there is some HTML and VBA coding.
I am very new to coding as well, learning as I need.
When the macro runs it brings back a number in cell B7, though this number can change (formula to another tab).
My issue is when the number is returned, a positive number is highlighted in green and a negative in red, through conditional formatting, i cannot figure out how to have this change in the email, it will simply bring back black, however if i write code in HTML for red it will always be red, and vice-versa for green.
Part of this code is from rondebruin which i changed up fo the HTML portion.
Any suggestion on how i can accomplish this?
I am open to any suggestions in the structure of my coding, i am looking to improve.
I have the following code that emails the status of a workbook so there is some HTML and VBA coding.
I am very new to coding as well, learning as I need.
When the macro runs it brings back a number in cell B7, though this number can change (formula to another tab).
My issue is when the number is returned, a positive number is highlighted in green and a negative in red, through conditional formatting, i cannot figure out how to have this change in the email, it will simply bring back black, however if i write code in HTML for red it will always be red, and vice-versa for green.
Part of this code is from rondebruin which i changed up fo the HTML portion.
Any suggestion on how i can accomplish this?
I am open to any suggestions in the structure of my coding, i am looking to improve.
Code:
Sub Email_DailyReport_()'Working in Excel 2000-2016
'This example send the last saved version of the Activeworkbook
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim OutApp As Object
Dim outMail As Object
Dim MailTo As String
Dim CopyTo As String
Dim SubjectEmail As String
Dim Emailbody As String
Dim STo As String
MailTo = Worksheets("Email Dist.").Range("b2:b2") 'modify range of emails to send to:
CopyTo = Worksheets("Email Dist.").Range("b3:b3") 'modify range of emails to cc:
SubjectEmail = Worksheets("Email Dist.").Range("b4:b4") 'subject of email
EmailBody1 = Worksheets("Email Dist.").Range("b5:b5")
EmailBody2 = Worksheets("Email Dist.").Range("b6:b6")
EmailBody3 = Worksheets("Email Dist.").Range("b7:b7")
EmailBody4 = Replace(Worksheets("Email Dist.").Range("b8:b8"), vbCrLf, "<br>")
EmailBody5 = Worksheets("Email Dist.").Range("b9:b9") 'modify range of emails to send to:
EmailBody0 = EmailBody2 & EmailBody3 & EmailBody4 & EmailBody5
'HTML coding for formatting the body of the email
'**********************************************************************************************************
SIGN1 = "<p><span style='font-size:11pt'><span style='font-family:Arial,Helvetica,sans-serif'><strong>Jeremy</strong>" 'everything below is the signature portion - for here change the name
SIGN2 = "<br />"
SIGN3 = "Financial Analyst / Analyste financier" 'change title
SIGN4 = "<br />"
SIGN5 = "<span style='color:#ff0000'><strong>joe </strong></span>| <span style='color:#0000ff'>www.joe.com</span> | Email: <span style='color:#0000ff'>joe@joe.com</span>" 'change email in signature
SIGN6 = "<br />"
SIGN7 = "Dir 555.555.5555" 'change extension the phone number
SIGN8 = "<br />"
SIGN9 = "Montreal</span></span>" 'change address if need be
SIGN10 = "</p>"
SIGN0 = SIGN1 & SIGN2 & SIGN3 & SIGN4 & SIGN5 & SIGN6 & SIGN7 & SIGN8 & SIGN9 & SIGN10
'**********************************************************************************************************
Set OutApp = CreateObject("Outlook.Application")
Set outMail = OutApp.CreateItem(0)
On Error Resume Next
With outMail
.To = MailTo
.CC = CopyTo
.BCC = ""
.Subject = SubjectEmail
.HTMLBody = EmailBody1 & _
"Click on this link to open the file : " & _
"<A HREF=""file://" & ActiveWorkbook.FullName & _
""">Daily Report</A>" & _
EmailBody0 & SIGN0
'.Attachments.Add ActiveWorkbook.FullName 'Remove this if link is inclucded if link not included then remove everything betweem BODY0 and SIGN0 - represents the hyperlink portion
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Display True 'or use .Send - using send prompts an authorization to send emails from excel, better to use display to see the email and send out. much faster as well
End With
On Error GoTo 0
Set outMail = Nothing
Set OutApp = Nothing
MsgBox "Email Sent"
End Sub
[code\]
I would post the workbook as well but, it seems i do not have permission.
[IMG]https://ibb.co/fkXN75[/IMG]
Much appreciated,
Regards.