Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-29-2018, 05:32 PM
Alex Cheng Alex Cheng is offline Word VBA Macro Needed to Crop & Resize Pictures Windows 10 Word VBA Macro Needed to Crop & Resize Pictures Office 2007
Novice
Word VBA Macro Needed to Crop & Resize Pictures
 
Join Date: Nov 2018
Location: Denver, Colorado
Posts: 2
Alex Cheng is on a distinguished road
Default Word VBA Macro Needed to Crop & Resize Pictures

Hi Everyone, first post here so please bear with me if I'm not posting in the right place.

I'm a real estate appraiser and I often need to insert various digital photos of property within my reports that are written in MS Word. I'm currently using a macro to shrink down the images I've inserted into my Word documents so that they fit into the width of the document. The macro I've been using looks like this:

Public Sub ResizePictures()
Dim oDoc As Document, oShape As InlineShape
Set oDoc = Application.ActiveDocument

For Each oShape In oDoc.InlineShapes
oShape.Width = 216
Next oShape

Set oDoc = Nothing


End Sub

This macro works great when the orginal images are of the same size and aspect ratio, as they would be coming from a digital camera, however, I now need to screen grab images (using the built in windows Snipping Tool) from online sources like Google Maps and because these screen grab images now have variable sizes and aspect ratios, this macro cannot reduce the photos in a consistent manner, and as a result, the shrunken images end up being different sizes in the Word document. I think this has to do with the locking aspect ratio of the images.

I am hoping that someone could help me modify this macro to account for variable image sizes and aspect ratios. I'm thinking the easiest method might be to crop the screen grab images so that they are in a standard aspect ratio (something like 3:2), and then shrinking the images down as I have been. Naturally the cropping must be minimal so that the image doesn't lose its integrity, but still get to a constant aspect ratio before they are shrunk down. Perhaps there is a better way to do this, but not knowing much about editing images, I'm certainly open to any suggestions that may produce the desired results.

I hope I've provided enough information to at least get the ball rolling, but please let me know if there are any details missing. I thank you all in advance for your help.
Reply With Quote
  #2  
Old 11-29-2018, 09:02 PM
gmayor's Avatar
gmayor gmayor is offline Word VBA Macro Needed to Crop & Resize Pictures Windows 10 Word VBA Macro Needed to Crop & Resize Pictures Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If you insert the images into table cells of fixed width, the image will shrink to the width of the table cell without the need for a macro and the height of the cell will grow to accommodate the height of the picture.

OR

Add the Format Frame ... command to your QAT (Quick Access Toolbar) and insert a frame to hold the pictures. As with table cells, pictures will shrink to the width of the frame and the height will grow as required. Both can be inserted with or without borders.

If you are doing a lot of work with image captures investigate SnagIt which has lots of useful image editing tools and capture options.

You may also find http://www.gmayor.com/photo_gallery_template.html useful.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-29-2018, 09:28 PM
macropod's Avatar
macropod macropod is offline Word VBA Macro Needed to Crop & Resize Pictures Windows 7 64bit Word VBA Macro Needed to Crop & Resize Pictures Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted (and answered) at: http://www.vbaexpress.com/forum/show...esize-Pictures
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 11-30-2018, 10:54 AM
Alex Cheng Alex Cheng is offline Word VBA Macro Needed to Crop & Resize Pictures Windows 10 Word VBA Macro Needed to Crop & Resize Pictures Office 2007
Novice
Word VBA Macro Needed to Crop & Resize Pictures
 
Join Date: Nov 2018
Location: Denver, Colorado
Posts: 2
Alex Cheng is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
If you insert the images into table cells of fixed width, the image will shrink to the width of the table cell without the need for a macro and the height of the cell will grow to accommodate the height of the picture.

OR

Add the Format Frame ... command to your QAT (Quick Access Toolbar) and insert a frame to hold the pictures. As with table cells, pictures will shrink to the width of the frame and the height will grow as required. Both can be inserted with or without borders.

If you are doing a lot of work with image captures investigate SnagIt which has lots of useful image editing tools and capture options.

You may also find http://www.gmayor.com/photo_gallery_template.html useful.
Thanks for suggesting Snagit. It does exactly what I need, which is getting a screen capture at a constant size and aspect ratio. This alleviates the need adjust the size and aspect ratio after the fact. Thank you for your help. Much appreciated.
Reply With Quote
  #5  
Old 09-23-2021, 12:57 PM
James Martin James Martin is offline Word VBA Macro Needed to Crop & Resize Pictures Windows 10 Word VBA Macro Needed to Crop & Resize Pictures Office 2019
Novice
 
Join Date: Sep 2021
Posts: 7
James Martin is on a distinguished road
Default

I've got a similar problem. But resolved if images are embedded in Outlook emails via customer mobiles, and not classed as attachments. If I forward the customer's email and copy the Forwarded Email Body and paste H in a docx, the images are wrapped/justified. Just trying to code this, I have one attempt from Page Not Found - Slipstick Systems which I have changed to docx with header and attachment list which my method doesn't do. Haven't managed to add to the code to resolve yet, looks like going to have to code my way and paste H and sort out a full header.
Reply With Quote
  #6  
Old 10-04-2021, 11:15 AM
James Martin James Martin is offline Word VBA Macro Needed to Crop & Resize Pictures Windows 10 Word VBA Macro Needed to Crop & Resize Pictures Office 2019
Novice
 
Join Date: Sep 2021
Posts: 7
James Martin is on a distinguished road
Default

I'm testing this, so far ok. May need to exempt TIFF files that we occasionally get from customers as additional pages can be hidden.


Sub ResizePicturesWithinMarginIF()

Dim oDoc As Document, oShape As InlineShape
Set oDoc = Application.ActiveDocument

For Each oShape in oDoc.inlineShapes
If oShape.Width > 510 Then
oShape.LockAspectRatio = True
oShape.Width = 510
End If

If oShape.Height > 660 Then
oShape.LockAspectRatio = True
oShape.Height = 660

End If


Next

Set oDoc = Nothing

End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA Macro Needed to Crop & Resize Pictures Macro to resize all objects & pictures? Fabulist Word VBA 4 01-19-2017 01:30 AM
Add pictures in specific parts of the document and resize them automatically - MS Word 2013 Andrew_G93 Word 6 11-10-2015 09:00 AM
A macro needed to crop to fit all images at once shaivya1998 PowerPoint 8 08-14-2015 08:11 AM
Word VBA Macro Needed to Crop & Resize Pictures Help Creating Macro to Crop/Resize Images ineedmacrohelp Word VBA 1 08-06-2015 06:46 AM
Word VBA Macro Needed to Crop & Resize Pictures Resize multiple pictures in a Word 2010 table JBA479 Word VBA 1 01-24-2014 08:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:34 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