Image placement in an e-mail via VBA

RAZE

New Member
Joined
Feb 27, 2020
Messages
6
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. Web
Hello everyone,

I have a macro-code that attaches a picture in the e-mail body from the excel Activesheet. My problems are:
  1. Is there a possibility to place the image above "Thank you" line ?
  2. If I want to insert a second picture how can I modify the code so that the Picture2 will be placed bellow Picture1 (currently it's placing in the right of Picture1)
Any ideas ?
VBA Code:
Sub create_email_2()
         Dim oApp As Outlook.Application
         Dim email As Outlook.MailItem

         Dim inspect As Outlook.Inspector
         Dim content As Object

         Set oApp = New Outlook.Application
         Set email = oApp.CreateItem(olMailItem)
         With email
         .To = "magic@gmail.com"
         .Subject = "E-mail2"
         .htmbody = "Hello" & "</p>" _
         & "Please see bellow current status" & "</p>" _
         & "Thank you" & "</body></html>"

         .Display
         Set inspect = email.GetInspector
         Set content = inspect.WordEditor

         ActiveSheet.Pictures(1).Copy
         content.Application.Selection.Start = Len(.Body)
         content.Application.Selection.Paste

         'ActiveSheet.Pictures(2).Copy
         'content.Application.Selection.Start = Len(.Body)
         'content.Application.Selection.Paste
          .Save
         '.Send
         End With

         End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Cross posted Image placement in an e-mail via VBA - OzGrid Free Excel/VBA Help Forum

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Let's I have changed the way I have structured the e-mail content and before adding the snip I added some extra lines that insert a range from Activesheet.
VBA Code:
Range("J5:U9").Copy
contentR.Application.Selection.Start = Len(.Body)
contentR.Application.Selection.Paste

Problem is that for some e-mails I get error 1004 - Copy method of picture class failed highlighting the copy codeline and if I click debug and press F5 the macro resumes from where it broke - with job complete. For a few e-mails is ok to press debug and F5 but for more than 100 is not funny.
I have tried with an On error resume next but for the e-mails where the error would occur I get them incomplete (no range and no image inserted).

Any ideea on how to bypass it ?
 
Upvote 0

Forum statistics

Threads
1,214,405
Messages
6,119,320
Members
448,887
Latest member
AirOliver

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