Originally Posted by
KIRAN.SHETTY
"How can you make this dyncamic to ensure that it picks different images based on situation supplied"
"Const MyPicture = "My Picture.jpg""
Hi and welcome to VbaExpress forum!
This code displays file picker dialog to choose an image and embed it into email:
Sub Main() Dim PathName As String
With Application.FileDialog(msoFileDialogFilePicker)
'.InitialFileName = "D:\Temp\" ' <-- Use this line to set a default folder
If .Filters.Count > 0 Then .Filters.Delete
.Filters.Add "Images", "*.gif; *.png; *.jpg; *.jpeg", 1
.AllowMultiSelect = False
If .Show = False Then Exit Sub
PathName = .SelectedItems(1)
End With
Call EmbedPicture(PathName)
End Sub
Sub EmbedPicture(PathName As String)
Dim MyPicture As String
MyPicture = Mid(PathName, InStrRev(PathName, Application.PathSeparator) + 1)
With CreateObject("Outlook.Application").CreateItem(0)
.Attachments.Add PathName
.HTMLBody = "<html><p>This is a picture</p>" & _
"<img src=cid:" & Replace(MyPicture, " ", "%20") & _
"<p>Best Regards,</p>" & _
"<p>" & UCase(Environ("USERNAME")) & "</p></html>"
.Display
End With
End Sub
Regards