1

I need to use the Snipping Tool to capture a few screenshots, then copy & paste it into my Outlook Email template.

After I paste the pictures into the Email template, I want the images to change to a width of 9cm (255 ps) in a click of a button. The codes behind the button will run on the current item open.

That is, the code will have to run through the current item that is open and identify the image object, and run the codes to change the width of the image (with aspect ratio turned on).

I have done a little coding as shown below but I can't make it run. Can anyone help me on this?

p.s. I did a search and figured that ShapeRange only apply for Word, Powerpoint, Excel, Project, etc.

Option Explicit

Sub ChangeWidth()

Dim objApp As Outlook.Application
Dim objItem As Outlook.MailItem
Dim OrigShape As ShapeRange
Dim image As Object

Set objApp = Application
Set objItem = objApp.ActiveInspector.CurrentItem

objItem.ShapeRange.LockAspectRatio = msoTrue
objItem.ShapeRange.Width = 255.1181103

End Sub
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Jing Yi
  • 203
  • 4
  • 15

1 Answers1

1

You need to use InlineShapes :

Option Explicit

Sub ChangeWidth()

Dim objApp As Outlook.Application
Dim objItem As Outlook.MailItem
Dim iShape As InlineShape
Dim image As Object

Set objApp = Application
Set objItem = objApp.ActiveInspector.CurrentItem

For Each shp In objItem.InlineShapes
    If shp.HasPicture Then
        shp.LockAspectRatio = msoTrue
        'shp.ScaleHeight = 150
        'shp.ScaleWidth = 150
        'or
        shp.Width = 255.1181103
    End If
Next

End Sub
R3uK
  • 14,417
  • 7
  • 43
  • 77
  • Hi R3uK, Thanks for your answer! However, .HasPicture only works for ContactItems. Therefore, I could not run the program either. Do you know how can I use VBA codes to identify if there is a image in the Email Body? – Jing Yi Oct 20 '15 at 09:23
  • No problem, glad I could help! Does it fix your problem? if it does please validate (the tick right under up/down vote) the answer to mark your question as solved! ;) – R3uK Oct 20 '15 at 09:25
  • I just saw the edit of your comment. I haven't in mind the way to identify this, I'll take a look too but if you find the right link or something, post here, I'll improve my answer to be fully functioning! ;) – R3uK Oct 20 '15 at 09:29
  • I've look around and it doesn't seems easy to identify images into the body of an email with outlook... It is for attachments : https://msdn.microsoft.com/en-us/library/Aa168469.aspx But if you want to dig deeper, you'll probably need to go through `HTMLBody` and parse HTML to find `` and work with that... Pretty heavy stuff but still doable (I think). – R3uK Oct 20 '15 at 09:57
  • Thank you R3uk for your help! I am thinking of transposing the codes to Excel VBA and send an Email from there. I will post any questions and solutions in this thread if I found one. – Jing Yi Oct 21 '15 at 04:57
  • @JJ2015 : Don't post new questions here, eventually some links that might be really relevant to your issue. But as I said you'll have to go through HTMLBody to edit HMTL to set the size of the picture, which would be far too much effort for a little result, so the Excel part seems far more interesting! So please validate (the tick right under the up/down vote) this answer or delete question, before asking a new one on your new approach! ;) – R3uK Oct 21 '15 at 14:37