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
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
48,287
Office Version
  1. 365
Platform
  1. Windows
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.
 

RAZE

New Member
Joined
Feb 27, 2020
Messages
6
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. Web
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 ?
 

Watch MrExcel Video

Forum statistics

Threads
1,114,314
Messages
5,547,171
Members
410,775
Latest member
alal1030
Top