iptsatzzo
02-23-2015, 09:24 PM
G'day All,
I have a macro adapted from code obtained from multiple web-sources which works as intended in a Word 2010 doc (*.docx), but not in a Word 2007 doc (*.doc), still in the Word 2010 environment.
The goal of the macro is to paste a picture (shape, or inlineshape), set the width to 18cm while maintaining the original aspect ratio, then "reverse crop" the bottom of the picture by 0.5cm. Working with a "*.doc" format document in Word 2010, the result is a picture with the correct cropping and width, but the aspect ratio has changed, distorting the picture.
Eg:
Original picture size (height/width in cm): 24.26/29.16
Pasted picture size: 13.73/16.49 (57/57% of original)
If pasted to a "*.docx" (Word 2010) format document, the result of running the macro is: 15.28/18.00 (62/62% of original)
If pasted to a "*.doc" (Word 2007) format document, the result of running the macro is: : 13.99/18.00 (57/62% of original)
The full code follows (it's not long :)):
Sub Paste_SizeAndCrop_FEH_DEH()
Dim Rng As Range
Set Rng = Selection.Range
With Rng
.Paste
If .ShapeRange.Count = 1 Then
With .ShapeRange(1)
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(18)
With .PictureFormat
.CropBottom = CentimetersToPoints(-0.5)
End With
End With
ElseIf .InlineShapes.Count = 1 Then
With .InlineShapes(1)
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(18)
With .PictureFormat
.CropBottom = CentimetersToPoints(-0.5)
End With
End With
End If
End With
End Sub
I can't replicate the error by manually following the actions of the macro, and am out of ideas.
Any assistance would be appreciated!
Thanks!
I have a macro adapted from code obtained from multiple web-sources which works as intended in a Word 2010 doc (*.docx), but not in a Word 2007 doc (*.doc), still in the Word 2010 environment.
The goal of the macro is to paste a picture (shape, or inlineshape), set the width to 18cm while maintaining the original aspect ratio, then "reverse crop" the bottom of the picture by 0.5cm. Working with a "*.doc" format document in Word 2010, the result is a picture with the correct cropping and width, but the aspect ratio has changed, distorting the picture.
Eg:
Original picture size (height/width in cm): 24.26/29.16
Pasted picture size: 13.73/16.49 (57/57% of original)
If pasted to a "*.docx" (Word 2010) format document, the result of running the macro is: 15.28/18.00 (62/62% of original)
If pasted to a "*.doc" (Word 2007) format document, the result of running the macro is: : 13.99/18.00 (57/62% of original)
The full code follows (it's not long :)):
Sub Paste_SizeAndCrop_FEH_DEH()
Dim Rng As Range
Set Rng = Selection.Range
With Rng
.Paste
If .ShapeRange.Count = 1 Then
With .ShapeRange(1)
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(18)
With .PictureFormat
.CropBottom = CentimetersToPoints(-0.5)
End With
End With
ElseIf .InlineShapes.Count = 1 Then
With .InlineShapes(1)
.LockAspectRatio = msoTrue
.Width = CentimetersToPoints(18)
With .PictureFormat
.CropBottom = CentimetersToPoints(-0.5)
End With
End With
End If
End With
End Sub
I can't replicate the error by manually following the actions of the macro, and am out of ideas.
Any assistance would be appreciated!
Thanks!