Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-31-2017, 09:29 AM
Strifly Strifly is offline Picture inserting,resizing and rotating with Macro depending on height and width Windows 10 Picture inserting,resizing and rotating with Macro depending on height and width Office 2007
Novice
Picture inserting,resizing and rotating with Macro depending on height and width
 
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
  #2  
Old 11-01-2017, 06:36 AM
gmaxey gmaxey is offline Picture inserting,resizing and rotating with Macro depending on height and width Windows 7 32bit Picture inserting,resizing and rotating with Macro depending on height and width Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Not exactly sure what you are after but maybe:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey, http://gregmaxey.com/word_tips.html, 11/1/2017
Dim strFile As String
Dim oILS As InlineShape, oShp As Shape
Dim bRotate As Boolean
  
  bRotate = False
  With Dialogs(wdDialogInsertPicture)
    .Display
    If .Name <> "" Then strFile = .Name
  End With
  If strFile <> vbNullString Then
    Set oILS = Selection.InlineShapes.AddPicture(strFile)
    With oILS
      If .Width < .Height Then
        Set oShp = .ConvertToShape
        oShp.IncrementRotation 90
        bRotate = True
      End If
    End With
    If bRotate Then Set oILS = oShp.ConvertToInlineShape
    With oILS
      .LockAspectRatio = msoTrue
      If bRotate Then
        .Width = CentimetersToPoints(4.318)
      Else
        .Height = CentimetersToPoints(4.318)
      End If
      MsgBox .Height & " " & .Width
    End With
 End If
 Set oILS = Nothing: Set oShp = Nothing
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 11-05-2017, 03:18 AM
Strifly Strifly is offline Picture inserting,resizing and rotating with Macro depending on height and width Windows 10 Picture inserting,resizing and rotating with Macro depending on height and width Office 2007
Novice
Picture inserting,resizing and rotating with Macro depending on height and width
 
Join Date: Oct 2017
Posts: 2
Strifly is on a distinguished road
Default

Hey Greg!

It Works !!! exactly what I was after !!
Thank you very much !

Eli.
Reply With Quote
Reply

Tags
height, picture, width



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help - Run-time error 91 - VBA for inserting and formatting text depending on style mtrborges Word VBA 2 02-08-2015 11:35 PM
Lost photo content after rotating photos using MS Picture Manager jefflyon Office 1 08-22-2014 11:57 PM
Picture inserting,resizing and rotating with Macro depending on height and width Height and Width blank - Excel Chart in Powerpoint Metronome PowerPoint 1 04-06-2012 06:20 AM
Picture inserting,resizing and rotating with Macro depending on height and width Rotating a picture in a picture box Cath5000 PowerPoint 1 01-18-2012 03:04 PM
Picture inserting,resizing and rotating with Macro depending on height and width Word is inserting bold page-width lines without permission! kozureokami Word 6 05-22-2011 02:59 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft