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
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: