MS Word Macro to change image width
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

I just want to change the image width to "7" for every image in my DOC file.

e.g. just type the number 7 here for all images:

https://i.stack.imgur.com/TUeuY.png

But i'd like the image to retain it's aspect ratio of course.

awarded to mashtullah
Tags
macro

Crowdsource coding tasks.

1 Solution

Winning solution

I have a solution in VBA,In your word document press CTRL+F11 and the VBA editor will be opened.

Paste the code below and you just run resizeImages() , it will pop an inputbox asking you to enter the desired width in inches to set all images. After that, it resizes all the images on your document...

Sub resizeImages()
Dim widthInches As Long
Dim Shape As InlineShape
widthInches = 7
widthInches = InputBox("Please enter the image width in inches to set", "Image Resizer", widthInches)
For Each Shape In ActiveDocument.InlineShapes
With Shape
.LockAspectRatio = msoTrue
.Width = widthInches * 72
End With
Next Shape
Word.Application.Activate
End Sub

This should work for you, try it out and let me know if you get any hitches...

it says compiler herror https://i.imgur.com/EDBYwsj.jpg
tonloc 8 months ago
Its because at the top of your module file you have specified Option Explicit but i have modified the solution by adding the Shape variable declaration so if you run now it should work fine...
mashtullah 8 months ago