VBA HTML EMAIL +Conditional Formatting

Stonierman1

New Member
Joined
Aug 6, 2014
Messages
4
Hello,
I currently have a piece of VBA code that converts an excel selection into a HTML email. In the workbook there is a number of specific conditional formatting formulas that are being used. When I run the HTML email macro it populates the selection in outlook (.display) but the conditional formatting is completely messed up... advice?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Did you set the email body to HTML format?

Code:
 .BodyFormat = olFormatHTML   

  .HTMLBody = _   

      [COLOR=#000000][FONT=Consolas]"<HTML><BODY>Enter the message text here. </BODY></HTML>" [/FONT][/COLOR]
  
  .Display
 
Last edited:
Upvote 0
I can get the plain text to work but you need HTML tags before and after the "Enter the message text here" line.
 
Upvote 0
HTML isnt the issue. The email populates with everything I want in it, the only issue is that the conditional formatting formulas that are in the excel workbook come over to outlook and visually change the doc. I almost want to paste the selection as an image in the outlook email.
 
Upvote 0
just a test thought, can you copy paste into outlook directly

I know if I want formatting to follow I have to paste into word, then copy and paste it back
 
Upvote 0
I was actually able to figure it out.... If any of you are interested, I can paste the code if you would like.
 
Upvote 0
always worth pasting the code between tags on here for others to find
 
Upvote 0
Sub Email()
'
' Email Macro
'

Application.ScreenUpdating = False
Workbooks("Real-Time Dashboard_2.0.xlsm").Save

'Unprotect Sheet

Dim Sh As Worksheet
Dim myPassword As String
myPassword = "lucasmyass"

For Each Sh In ActiveWorkbook.Worksheets
Sh.Unprotect Password:=myPassword
Next Sh

'Email

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object


Set rng = Application.Intersect(ActiveSheet.UsedRange, Range("E3:AB81"))
rng.SpecialCells(xlCellTypeVisible).Select


On Error GoTo 0

If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

Dim TempFilePath As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

'Email Details
On Error Resume Next
With OutMail
.To = "SIC2 (Student Inquiry Coordinators 2)"
.CC = ""
.BCC = ""
.Subject = "Real Time Update"
.HTMLBody = "<span LANG=EN>" _
& "<p class=style2><span LANG=EN><font FACE=Calibri SIZE=3>" _


'Create the image as a JPG file
Call createJpg("Dash1", "E4:Z80", "DashboardFile")
'we attached the embedded image with a Position at 0 (makes the attachment hidden)
TempFilePath = Environ$("temp") & "\"
.Attachments.Add TempFilePath & "DashboardFile.jpg", olByValue, 0

'Then we add an html <img src=''> link to this image
'Note than you can customize width and height - not mandatory

.HTMLBody = .HTMLBody & "" _
& "<img src='cid:DashboardFile.jpg'" & "width='1300' height='1300'><br>" _

.Display
'.Send
End With
On Error GoTo 0

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub


Sub createJpg(Namesheet As String, nameRange As String, nameFile As String)
ThisWorkbook.Activate
Worksheets("Dash1").Activate
Set Plage = ThisWorkbook.Worksheets(Namesheet).Range(nameRange)
Plage.CopyPicture
With ThisWorkbook.Worksheets("Dash1").ChartObjects.Add(Plage.Left, Plage.Top, Plage.Width, Plage.Height)
.Activate
.Chart.Paste
.Chart.Export Environ$("temp") & "\" & nameFile & ".jpg", "JPG"
End With
Worksheets("Dash1").ChartObjects(Worksheets("Dash1").ChartObjects.Count).Delete
Set Plage = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,606
Messages
6,125,814
Members
449,262
Latest member
hideto94

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