How do I adjust the size of the pasted image in Outlook email

0 votes

viewing older questions on this site I was able to locate the code I required, but I was unsuccessful in changing the image's dimensions (height and width). Can you assist me?

Sub SendEmail()
    'Open a new mail item
    Set outlookApp = CreateObject("Outlook.Application")
   
    Set OutMail = outlookApp.CreateItem(olMailItem)
    
    With OutMail
        .To = ""
        .Subject = "** Please confirm Timesheet by 10:30AM **"
        .Importance = olImportanceHigh
        .Display
    End With

    'Get its Word editor
    Set wordDoc = OutMail.GetInspector.WordEditor

    'To paste as picture
    rng.Copy
    wordDoc.Range.PasteSpecial , , , , wdPasteBitmap

    OutMail.HTMLBody = "Timesheets Submitted by " & "Marco" & "<br>" & _
    vbNewLine & OutMail.HTMLBody
End Sub

I tried to create some commands to resize the image size but without success.

Feb 27, 2023 in Others by Kithuzzz
• 38,000 points
1,421 views

1 answer to this question.

0 votes

Try this :

Option Explicit

'~~> Since we are working using Late Binding

'~~> Outlook Constants
Private Const olImportanceHigh = 2
Private Const olMailItem = 0

'~~> Word Constant
Private Const wdChartPicture = 13

Sub SendEmail()
    '~~> Worksheet Operations
    Dim ws As Worksheet
    Dim rng As Range
    Dim pic As Picture
        
    '~~> Change this to the relevant sheet
    Set ws = Sheet1
    '~~> Change this to the relevant range
    Set rng = ws.Range("A1:A15")
    
    '~~> Copy the range and paste it in a picture object
    rng.Copy
    Set pic = ws.Pictures.Paste
    
    '~~> Set the dimensions here
    With pic.ShapeRange
        .LockAspectRatio = msoTrue
        .Height = 200
        .Width = 200
    End With
    
    '~~> Outlook Operations
    Dim OutApp As Object
    Dim OutMail As Object
 
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(olMailItem)
    
    With OutMail
        .To = ""
        .Subject = "** Please confirm Timesheet by 10:30AM **"
        .Importance = olImportanceHigh
        .Display
    End With

    Dim wordDoc As Object
    Set wordDoc = OutMail.GetInspector.WordEditor
    
    '~~> Cut the picture and paste in email
    pic.Cut
    DoEvents
    
    wordDoc.Range.pasteandformat wdChartPicture

    OutMail.HTMLBody = "Timesheets Submitted by Marco" & _
                       "<br>" & _
                       vbNewLine & OutMail.HTMLBody
End Sub
answered Mar 18, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
0 answers

How do I determine the size of my array in C?

How do I determine the size of ...READ MORE

May 1, 2022 in Others by Kichu
• 19,040 points
495 views
0 votes
1 answer

How do I get the current date and time in PHP?

The time would go by your server ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
725 views
0 votes
0 answers

How can I get the intersection, union, and subset of arrays in Ruby?

I want to develop many methods for ...READ MORE

Aug 8, 2022 in Others by krishna
• 2,820 points
531 views
0 votes
1 answer

How do you calculate the Quintile for groups of rows in Excel?

Use this formula: =MAX(1,ROUNDUP(10*PERCENTRANK($C:$C,$C2,4),0)) To divide into whichever many ...READ MORE

answered Oct 17, 2022 in Others by narikkadan
• 63,600 points
1,374 views
0 votes
1 answer

Embed picture in outlook mail body excel vba

The image needs to be added and ...READ MORE

answered Dec 16, 2022 in Others by narikkadan
• 63,600 points
5,496 views
0 votes
1 answer

VBA How to extract the date and time of arrival of a answered email

Use MailItem.ReceivedTime property. I hope this helps you ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,600 points
2,914 views
0 votes
1 answer

Error populating email body from word documents

There is no need to use late ...READ MORE

answered Jan 15, 2023 in Others by narikkadan
• 63,600 points
1,568 views
0 votes
1 answer

Export All appointments and meetings (including recurring meetings) Excel VBA

However, when I use the code above ...READ MORE

answered Feb 13, 2023 in Others by narikkadan
• 63,600 points
1,720 views
0 votes
1 answer

How do I combine the first character of a cell with another cell in Excel?

Try this: =CONCATENATE(LEFT(A1,1), B1) READ MORE

answered Nov 7, 2022 in Others by narikkadan
• 63,600 points
1,499 views
0 votes
1 answer

In excel how do I reference the current row but a specific column?

Put a $ symbol in front of ...READ MORE

answered Oct 15, 2022 in Others by narikkadan
• 63,600 points
1,961 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP