Picture/Image/Attachment Resizing

Status
Not open for further replies.

Steven Proud

Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
In Word I had found some great VBA code to resize BOTH a selected item and all items in a word document.

FOR EXAMPLE IN WORD - TO RESIZE A SELECTED ITEM/PICTURE

Sub ResizePic40Percent()
'
' ResizePic Macro
'
' The macro first asks for a percentage by which you want to scale the selected image,
' offering 75 (75%) as the default. When you specify a percentage, the macro then checks
' to see if the selected graphic is an inline or a floating graphic.
' The reason for doing this is that the object specification is different in each case,
' as well as how the scaling is specified. Inline objects belong to the InlineShapes collection,
' while floating objects are set using the ShapeRange object.
'
Dim PecentSize As Integer
PercentSize = 40
If Selection.InlineShapes.Count > 0 Then
Selection.InlineShapes(1).ScaleHeight = PercentSize
Selection.InlineShapes(1).ScaleWidth = PercentSize
Else
Selection.ShapeRange.ScaleHeight Factor:=(PercentSize / 100), _
RelativeToOriginalSize:=msoCTrue
Selection.ShapeRange.ScaleWidth Factor:=(PercentSize / 100), _
RelativeToOriginalSize:=msoCTrue
End If
End Sub

FOR EXAMPLE IN WORD - TO RESIZE ALL ITEMS/PICTURES

Sub ResizeAllPictSize40Percent()
' If you want to resize all the graphics in your document by the same percentage,
' then you only need to modify the above macro so that it steps through each of
' the inline graphics and then each of the floating graphics.
Dim PercentSize As Integer
Dim oIshp As InlineShape
Dim oshp As Shape
PercentSize = 40
For Each oIshp In ActiveDocument.InlineShapes
With oIshp
.ScaleHeight = PercentSize
.ScaleWidth = PercentSize
End With
Next oIshp
For Each oshp In ActiveDocument.Shapes
With oshp
.ScaleHeight Factor:=(PercentSize / 100), _
RelativeToOriginalSize:=msoCTrue
.ScaleWidth Factor:=(PercentSize / 100), _
RelativeToOriginalSize:=msoCTrue
End With
Next oshp
End Sub

THE ABOVE VBA workks great!!!!!

So thought I would adapt this to Outlook since I have to always resize images and other stuff ALL DAY LONG.

The same code from WORD would NOT work in OUTLOOK :(

I found some other code that works IN OUTLOOK- TO RESIZE ALL ITEMS/PICTURES
It also works great!!!!


Public Sub ResizeAllPictSize40Percent()
' If you want to resize all the graphics in your document by the same percentage,
' then you only need to modify the above macro so that it steps through each of
' the inline graphics and then each of the floating graphics.
Set objDoc = ActiveInspector.WordEditor
Set objWord = objDoc.Application
Dim iShp As Word.InlineShape
Dim iSelection As Word.Selection
Dim PecentSize As Integer
PercentSize = 40

On Error Resume Next
For Each iShp In objDoc.InlineShapes
With iShp
If .ScaleHeight Then
.ScaleHeight = PercentSize
End If
If .ScaleWidth Then
.ScaleWidth = PercentSize
End If
End With
Next iShp
End Sub


MY PROBLEM,

I'm not best at VBA and I NEED to select ONLY one item of many and resize only that item.
I have tried many things without any luck or better understanding.
Help Please
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The problem is with this line:
For Each iShp In objDoc.InlineShapes

Rather than using for each ishp, you need to identify the selected shape and process it. If you know it's always the first shape on the page (or 2nd etc) you can call it by number ishp(1), otherwise you need to get the selected object.
 

Steven Proud

Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
The problem is with this line:


Rather than using for each ishp, you need to identify the selected shape and process it. If you know it's always the first shape on the page (or 2nd etc) you can call it by number ishp(1), otherwise you need to get the selected object.

I have tried to find a way to find "the selected object" without luck. for example, I cannot find a ishp(1).selected property for each? This is really my whole question.
Should I have asked this question in the topic of "Ask in Programming and Forums"? Is that what you meant. I am sorry, but my first post ever on any website - I'm a little behind the times at age 46.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
The forum doesn't really matter, although Michael has a better chance of seeing it. (He's the resident programming expert.) I'll move the thread there.

Have you tried using ishp(1) as the selected shape object?
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
The very first macro should do it. All you usually need to do to make a Word macro running in Outlook (2007 and higher) is to get a reference on the Word.Selection object. Here's a sample, add its lines to the first one before it accesses the Selection object.
 

Steven Proud

Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server 2013
The very first macro should do it. All you usually need to do to make a Word macro running in Outlook (2007 and higher) is to get a reference on the Word.Selection object. Here's a sample, add its lines to the first one before it accesses the Selection object.

Thank you very much for the information - I finally have this working with the following Code as my working code.

Public Sub ResizePic40Percent()

' ResizePic macro
' The macro first will attempt scale the selected image to the specified percentage,
' the macro then checks to see if the selected graphic is an inline or a floating graphic.
' The reason for doing this is that the object specification is different in each case,
' as well as how the scaling is specified. Inline objects belong to the InlineShapes collection,
' while floating objects are set using the ShapeRange object.

Dim Ins As Outlook.Inspector
Dim Document As Word.Document
Dim Word As Word.Application
Dim Selection As Word.Selection

Set Ins = Application.ActiveInspector
Set Document = Ins.WordEditor
Set Word = Document.Application
Set Selection = Word.Selection

Dim PecentSize As Integer
PercentSize = 40

On Error Resume Next

If Selection.InlineShapes.Count > 0 Then
Selection.InlineShapes(1).ScaleHeight = PercentSize
Selection.InlineShapes(1).ScaleWidth = PercentSize
Else
Selection.ShapeRange.ScaleHeight Factor:=(PercentSize / 100), _
RelativeToOriginalSize:=msoCTrue
Selection.ShapeRange.ScaleWidth Factor:=(PercentSize / 100), _
RelativeToOriginalSize:=msoCTrue
End If

End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Unhandled exception: picture argument should be an image BCM (Business Contact Manager) 0
witzker Outlook 2019 is cutting Picture Extension *.pn_ Using Outlook 3
E What does mean this icon at the picture attached? Using Outlook 2
P Outlook 2010: Missing tab - "Format/Picture Tools" HELP! Using Outlook 3
Diane Poremsky Displaying a Picture on a Contact Using Outlook 0
oliv- Reduce the size of picture attachments: programmatically Outlook VBA and Custom Forms 3
B Automatic picture download and changing email addresses Using Outlook 3
G Issues with accessing Outlook Contact Picture with VBA Outlook VBA and Custom Forms 4
iwshim mail merge and add the contact picture outlook 2013 Using Outlook 3
Paul Van Cotthem Outlook 2013 contact picture only visible in "People" view Using Outlook 4
R Embbedet Firmlogo als Attachment and Picture Using Outlook 1
P Outlook can not display picture inline. Using Outlook 7
P OL2010 - custom form contact picture Using Outlook 0
L How to inbed picture in new outgoing messae Using Outlook 2
T Word attached files open Word. Excel files open Picture Manager!! Using Outlook 2
R insert picture tab grey Using Outlook 1
D Sending mass e-mail (picture only) Using Outlook 1
F How to setup signature with Outlook 2007 with external picture Using Outlook 4
S How to insert a picture programatically Outlook VBA and Custom Forms 12
C insert a picture Outlook VBA and Custom Forms 1
S How to add icon(or picture) field for each contact in contacts view Outlook VBA and Custom Forms 6
M Reply with picture in body of message Outlook VBA and Custom Forms 2
O The linked image cannot be displayed Using Outlook 2
C "The linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file location" Using Outlook 1
O How to prevent image resize when pasting Using Outlook 2
T The Linked Image Cannot Be Displayed in Outlook Using Outlook 7
P Can't paste an image into a task Using Outlook 3
D Reply with a template loose the sender's embedded image Outlook VBA and Custom Forms 0
Y Images coming through as Cid:image in outlook Using Outlook 0
L Block email signature image Using Outlook 1
Diane Poremsky Image Quality in Signatures Using Outlook 0
O How to move contacts folder image of a drive Using Outlook 1
Q Why can't I copy image with embedded hyperlink from email to Word Using Outlook 0
G Image scaling on high DPI screens Using Outlook 1
P Select image in contact notes field and save as jpg Outlook VBA and Custom Forms 6
crazyboy Copying BCM database from backed up mounted image to new drive BCM (Business Contact Manager) 2
oj43085 Prevent Outlook from blocking image from a single source Using Outlook 4
J Image in original e-mail is hyperlinked when a reply with the image is hyerplinked Exchange Server Administration 1
Maybear Sudden change in Outlook, no image display, email no longer offers suggestions for address Using Outlook 8
T Error opening mail with pictures - "The linked image cannot be displayed" Using Outlook 3
G Create rule based on image in email body Using Outlook 1
I How to add image header to email Using Outlook 2
E Outllook 2010 Header Image Using Outlook 3
R Add image within email and not attachment Using Outlook 2
B Need help adding an image next to the Month Name in the header. Using Outlook 1
S Outlook 2k/2k3 Reply or Forward: Signature image replaced by original sender Using Outlook 3
A Vanishing signature image in Outlook 2010 Using Outlook 1
M Save embedded image in native format Using Outlook 6
C Email image problems Using Outlook 6
P disable image compression Using Outlook 5

Similar threads

Top