Hello, I have been doing a lot of searching, but I am struggling to find the code when late binding to embed a jpeg image in an outlook email body, while it is hidden in the attachments. I've tried numerous configurations online, my current code gives me an error of "array index out of bounds" at the .display line.
Here is my code:
'Dim Email variables
Dim objEmail As Object
Dim objApp As Object
Dim strContact As String
Dim strSendTo As String
Dim strSubject As String
Dim rCount as Integer
Dim WksBidLst as Worksheet
'rCount is for looping - I've excluded the loop references as that is working fine.
'Assign Email Variables
rCount = 12
strContact = WksBidList.Range("H" & rCount)
strSendTo = WksBidList.Range("K" & rCount)
strSubject = "Invitation to Bid " & WksBidList.Range("E1")
strUserName = WksBidList.Range("F" & rCount)
strPassword = WksBidList.Range("G" & rCount)
strCategory = WksBidList.Range("B" & rCount)
'Get Logo jpeg
Dim Strbody as string
Dim StrITBLogoFilePath As String
Dim ObjITBLogo As Object
Dim StrITBLogo As String
StrITBLogoFilePath = "M:\Preconstruction\DO NOT MOVE OR EDIT\ITB Files"
Debug.Print StrITBLogoFilePath
Set ObjITBLogo = CreateObject("Scripting.FileSystemObject").OpenTextfile(StrITBLogoFilePath & "image001.jpg")
Let StrITBLogo = ObjITBLogo.readall
ObjITBLogo.Close
'Body of Email
Strbody = "<src=cid:image001>" & StrITBLogoFilePath & "
" & "Dear.... "
'Create Email Item (NOTE 2nd attachment below works fine, didn't include sourcing for that)
Set objApp = CreateObject("Outlook.Application")
Set objEmail = objApp.CreateItem(0)
With objEmail
.To = strSendTo
.Subject = strSubject
.HTMLBody = Strbody
.attachments.Add StrITBLogoFilePath & "image001.jpg", 0
.attachments.Add (Application.ActiveWorkbook.Path & StrAttachSummary)
.Save
.Display
End With
'Clear Objects
Set objEmail = Nothing
Set objApp = Nothing
Set ObjDefaultSignature = Nothing
end Sub</src=cid:image001>
Here is my code:
'Dim Email variables
Dim objEmail As Object
Dim objApp As Object
Dim strContact As String
Dim strSendTo As String
Dim strSubject As String
Dim rCount as Integer
Dim WksBidLst as Worksheet
'rCount is for looping - I've excluded the loop references as that is working fine.
'Assign Email Variables
rCount = 12
strContact = WksBidList.Range("H" & rCount)
strSendTo = WksBidList.Range("K" & rCount)
strSubject = "Invitation to Bid " & WksBidList.Range("E1")
strUserName = WksBidList.Range("F" & rCount)
strPassword = WksBidList.Range("G" & rCount)
strCategory = WksBidList.Range("B" & rCount)
'Get Logo jpeg
Dim Strbody as string
Dim StrITBLogoFilePath As String
Dim ObjITBLogo As Object
Dim StrITBLogo As String
StrITBLogoFilePath = "M:\Preconstruction\DO NOT MOVE OR EDIT\ITB Files"
Debug.Print StrITBLogoFilePath
Set ObjITBLogo = CreateObject("Scripting.FileSystemObject").OpenTextfile(StrITBLogoFilePath & "image001.jpg")
Let StrITBLogo = ObjITBLogo.readall
ObjITBLogo.Close
'Body of Email
Strbody = "<src=cid:image001>" & StrITBLogoFilePath & "
" & "Dear.... "
'Create Email Item (NOTE 2nd attachment below works fine, didn't include sourcing for that)
Set objApp = CreateObject("Outlook.Application")
Set objEmail = objApp.CreateItem(0)
With objEmail
.To = strSendTo
.Subject = strSubject
.HTMLBody = Strbody
.attachments.Add StrITBLogoFilePath & "image001.jpg", 0
.attachments.Add (Application.ActiveWorkbook.Path & StrAttachSummary)
.Save
.Display
End With
'Clear Objects
Set objEmail = Nothing
Set objApp = Nothing
Set ObjDefaultSignature = Nothing
end Sub</src=cid:image001>