HTML Body Mail through VBA

pallab2110

New Member
Joined
Dec 1, 2012
Messages
1
Hi,

I am trying to send an HTML file through excel vba and want to show up the same in the body of the mail. The file does have some image in it. when I try to send it, the images do not show up in the mail body. All the texts are showing perfectly, only the images are not showing. I am using the below code. Can somebody help me to resolve this. Wanted to add one more thing here. When I open this html in IE, it gives a warning first that "some script or activeX content is blocked, do you want to download", after I click on download the content, it shows up perfectly. If my mail also shows some warning like this it would be great. Thanks in advance.

Sub pallab()


Dim mainWB As Workbook
Dim FROMID
Dim SendID
Dim CCID
Dim BCCID
Dim Subject
Dim Body
Dim olMail As mailitem
Dim aa As Range


Dim URL As String
Dim IE As InternetExplorer




Dim HTMLdoc As HTMLDocument
Dim html1 As String
Dim html2 As String
'Dim html3 As String
Dim html3 As HTMLStyleElement




Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim r As Long



'Saved from www vbaexpress com/forum/forumdisplay.php?f=17
URL = "file://C:\Projects\Email\Priority Banking Customer.html"
URL1 = "file://C:\Projects\Email\advt.htm"

Set IE = New InternetExplorerMedium

'With IE
' .navigate URL
' .Visible = True

'Wait for page to load
'While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend

'Set HTMLdoc = .document

'End With

IE.navigate URL1
IE.Visible = True

'Wait for page to load
While IE.Busy Or IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend
Application.Wait (Now + TimeValue("0:00:02"))

html2 = IE.document.DocumentElement.outerHTML







Set otlApp = CreateObject("Outlook.Application")
Set olMail = otlApp.CreateItem(olMailItem)
Set Doc = olMail.GetInspector.WordEditor
'Dim colAttach As Outlook.Attachments
'Dim oAttach As Outlook.Attachment

Set mainWB = ActiveWorkbook


FROMID = mainWB.Sheets("Mail").Range("B1").Value
SendID = mainWB.Sheets("Mail").Range("B2").Value
CCID = mainWB.Sheets("Mail").Range("B3").Value
BCCID = mainWB.Sheets("Mail").Range("B4").Value
Subject = mainWB.Sheets("Mail").Range("B5").Value
'Body = mainWB.Sheets("Mail").Range("B6").Value
html1 = "C:\Projects\Email\Priority Banking Customer.html"




mainWB.Activate
Sheets("Mail").Range("C20").Value = html2




With olMail
'.SenderEmailAddress = FROMID
.To = SendID
If CCID <> "" Then
.CC = CCID
End If
If BCCID <> "" Then
.BCC = BCCID
End If
.Subject = Subject
.BodyFormat = olFormatHTML
'add the image in hidden manner, position at 0 will make it hidden
.Attachments.Add "C:\Projects\Email\Priority Banking Customer.html", olByValue, 0

.HTMLBody = .HTMLBody & html2

.Display
.Send
End With

MsgBox ("you Mail has been sent to " & BCCID)

End Sub
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

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