I am trying to use Excel VBA to create an email regarding the Childrens Cancer Institute of Australia with a background image (CCIALittleGirl.jpg).
I then want to have text or a text box ideally over it with white bold text that I can populate at runtime.
I can add an image to the email (the commented out MyHTML part does that) but I can't seem to get a background image to load in, I am modifying code I found online somewhere but my HTML skills are pretty close to nill.
I am pretty sure this part is my issue:
<div style=""background-image: ""cid:CCIALittleGirl.jpg""
Here is the code I have so far, the MyHTML part doesn't do what I expect.
Private Sub EmailCopy()
Dim oApp, oMail As Object, MyHTML As String
Application.ScreenUpdating = False
On Error Resume Next
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(0)
'MyHTML = "<p>TempText</p>"
'MyHTML = MyHTML & "<img src=""cid:CCIALogo.jpg"">"
MyHTML = "<div style=""background-image: ""cid:CCIALittleGirl.jpg"""; height: 390px; width: 900px; color: rgb(0, 0, 0); margin-top: 0px; padding-left: 35px; padding-top: 25px;"">"
MyHTML = MyHTML & "my text appears here and on top of the image"
MyHTML = MyHTML & "</div>"
With oMail
.To = "Email@Email.com.au"
.Subject = "TEST"
.Attachments.Add "C:\Images\CCIA\CCIALogo.jpg"
.Attachments.Add "C:\Images\CCIA\CCIALittleGirl.jpg"
.HTMLBody = MyHTML
.Display
.Save
.Close False
End With
Application.ScreenUpdating = True
Set oMail = Nothing
Set oApp = Nothing
End Sub
Thanks for any help you can offer.
Replace
<div style=""background-image: ""cid:CCIALittleGirl.jpg""></div>
with this<div style="background-image: cid:CCIALittleGirl.jpg"></div>
Worked it out:
This successfully puts the image in as a background.
For completeness (in case anyone else has the same question) here is the complete solution: