• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA code to automate mail with pictures [SOLVED]

smittal

Member
Hi,


can anyone please suggest VBA code to automate mail that supports pictures also. a link is attached here in which i want add picture in outlook body well but its not supporting.


https://www.dropbox.com/s/98jk411zod6uea6/Ajanta%20confirmation%20voucher.xlsx


please suggest the code for same and also how we add Microsoft outlook signature in same.


Thanks in Advance for Same!!!..:)
 
Good morning to all,


i have used below code for same... please suggest what should i change in same to get the picture download in automate mail body:

[pre]
Code:
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2010
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim vbOK: vbOK = 1
Dim vbCancel: vbCancel = 2
Dim Message As String
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Sheets("sheet1").Select

Message = "Are you sure for sending email"
resp = MsgBox(Message, vbOKCancel, "Validation....")
If resp = vbOK Then
Set rng = Nothing
Set rng = ActiveSheet.UsedRange
'You can also use a sheet name
'Set rng = Sheets("YourSheet").UsedRange

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

On Error Resume Next
With OutMail
.To = "shweta@internetmoguls.in"
'.CC = "shweta@internetmoguls.in"
'.BCC = ""
.Subject = "Ajanta Vochure"
.HTMLBody = RangetoHTML(rng)
.Display   'or use .Send
End With
On Error GoTo 0

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

Set OutMail = Nothing
Set OutApp = Nothing
Else
MsgBox "operation cancelled by user", vbExclamation, "Revalidation...."
Sheets("sheet1").Select
Range("A7").Select
End If
End Sub

Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2010
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "/" & Format(Now, "dd-mmm") & ".htm"

'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With

'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With

'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")

'Close TempWB
TempWB.Close savechanges:=False

'Delete the htm file we used in this function
Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
[/pre]
i am very sorry,i had attached the Wrong file link.. correct link is mention below:-


https://www.dropbox.com/s/bzztl3yoy0mhjp9/Ajanta%20confirmation%20voucher.xlsm


Thanks in advance for same.
 
Gud Morning All,


i request you to please confirm whether it is possible to use pictures in automate email through VBA.


Many thanks in advance for same.
 
Hi Mittal ,


Please note that questions posted on weekends may or may not get quick answers. Even though it may be urgent for you , those who view and answer may have other priorities ; if you can , please wait till Monday evening.


Narayan
 
Back
Top