Add .jpg image to email

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,625
Office Version
  1. 365
Platform
  1. Windows
I am automating the sending of emails with dynamic text and various formatting being applied to specific paragraphs of the email body.

The paragraphs are being added as follows
VBA Code:
.HTMLBody = rngEmail.Offset(0, 3) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 4) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 5) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 6) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 7) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 8) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 9) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 10) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 11) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 12) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 13) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 14) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 15) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 16) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 17) & vbNewLine & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 18) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 19) & vbNewLine & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 20) & vbNewLine & vbNewLine & _
            rngEmail.Offset(0, 21)
Whilst this looks unecessary, each of the defined ranges (cells) contain something like the following to achieve the paragraph specific formatting
<P STYLE='font-size:20'><b>Text here is formatted according to the container</b>

When the above is added to the .HTMLBody, I get the required formatting

At the end of the email between a sign off and a web address, I want to insert a logo/.jpg file

The logo is specified in the rngemail.Offset(0,22) Cell as


When this is added to the email
None of the vbNewLine commands work but a new paragprah is spaced at an acceptable space below the paragraph above
The image is added at the end of the preceding text

What I expected to see was

PARAGRAPH ABOVE LOGO

LOGO IMAGE HERE

but what I'm seeing is

PARAGRAPH ABOVE LOGO LOGO IMAGE HERE

I have no idea how to make this work as Excel just doesn't want to do what it is being told to do!

Any help with this would be hugely appreciated!


TIA
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Whilst this looks unecessary, each of the defined ranges (cells) contain something like the following to achieve the paragraph specific formatting
<P STYLE='font-size:20'><b>Text here is formatted according to the container</b>

When the above is added to the .HTMLBody, I get the required formatting

At the end of the email between a sign off and a web address, I want to insert a logo/.jpg file

The logo is specified in the rngemail.Offset(0,22) Cell as


When this is added to the email
None of the vbNewLine commands work but a new paragprah is spaced at an acceptable space below the paragraph above
The image is added at the end of the preceding text

First, the vbNewLines shouldn't affect the look/layout of the email. They simply make the HTML code embedded in the email more readable. You could remove all the vbNewLines and the email should look the same, as long as the HTML is correct.

To embed the LogoFile.jpg image in the email you need the following HTML:

HTML:
<img src='cid:LogoFile.jpg' height=150>

Note that only the file name, without folder path is specified.

And you need code to attach the image file and set the PR_ATTACH_CONTENT_ID property for "LogoFile.jpg" (i.e. only the file name) - see Paste excel range into e-mail as JPEG (VBA).
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top