View Single Post
 
Old 10-31-2017, 09:29 AM
Strifly Strifly is offline Windows 10 Office 2007
Novice
 
Join Date: Oct 2017
Posts: 2
Strifly is on a distinguished road
Question Picture inserting,resizing and rotating with Macro depending on height and width

Hello everyone!

I'm new here and wondered if I can get some help

I'm unfamiliar with VBA but some-what succeeded to work with found codes in different forums while building a database in MS Access a few years ago...
Now I'm stuck with a pic-by-pic assembly manual that I need to prepare for work...

Shortly, I need to insert a picture into a dedicated space (in my case a cell in a table) while resizing it's height to 1.7" (4.318cm) and maintaining the aspect ratio.

I found the code I need but only understood the next problem only after printing, I need to determine with code which is longer height of the original picture or width and rotating the picture 90 degrees if height is longer than width, only then resizing it's height and maintaining the aspect ration to fit the cell in my table.

The code I found and played with a bit is this :

Sub PicSize()
'
' PicSize Macro
'
'
Dim oDialog As Dialog
Dim strFile As String
Dim oImage As Object
Dim oRng As Range
Set oDialog = Dialogs(wdDialogInsertPicture)
With oDialog
.Display
If .Name <> "" Then
strFile = .Name
End If
End With
If IlShp.Width < IlShp.Height Then
shp.IncrementRotation 90
End If
Set oImage = Selection.InlineShapes.AddPicture(strFile)
With oImage
.LockAspectRatio = msoTrue
.Height = CentimetersToPoints(4.318)
Set oRng = oImage.Range
End With
Set oDialog = Nothing
Set oImage = Nothing
Set oRng = Nothing
End Sub

Can somebody help?
Thanks,
Strifly.
Reply With Quote