PDA

View Full Version : [SOLVED:] Macro to paste bunch of images at desired size in microsoft Word 2010.



staicumihai
01-07-2016, 09:17 PM
Hello guys,

I want to make a macro that automatically resizes images (while preserving the height and weight ratio) when I paste them in Microsoft Word 2010.

What I have now is this:

Option Explicit

Sub desiredimension()
On Error Resume Next
Dim oShp As Shape
Dim iShp As InlineShape
Dim ShpScale As Double
With Selection
For Each iShp In .InlineShapes
With iShp
If .Type = wdInlineShapePicture Or wdInlineShapeLinkedPicture Then

.Height = 141.64
End If
End With
Next iShp
End With
End Sub

(but it doesnt do this automatically when I paste the images, I have to go and select them all and then apply the macro)

Thanks a lot for the previous responses, that helped and helps me a lot at work and have a nice day.

gmayor
01-07-2016, 10:56 PM
You can intercept the paste command and use it to paste and format e.g. as follows, but it will paste ALL images at the size you indicate.
See also http://www.gmayor.com/photo_gallery_template.html

Sub EditPaste()
Dim iShp As InlineShape
Dim oRng As Range
Set oRng = Selection.Range
oRng.Paste
For Each iShp In oRng.InlineShapes
With iShp
If .Type = wdInlineShapePicture Or wdInlineShapeLinkedPicture Then
.LockAspectRatio = msoTrue
.Height = 141.64
End If
End With
Next iShp
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub

staicumihai
01-08-2016, 11:34 PM
That is exaclty what I wanted, perfect!
Thanks a lot GMayor.