Skip to content

Word Resize Macro

Published: at 05:10 AM

The purpose of the macro is to allow users to resize an image to a predefined width in Microsoft Word while maintaining its aspect ratio with convenience.

Macro Code

Sub ImageResize()
'
' ImageResize Macro
'
Dim w As Double
Dim h As Double
Dim ew As Double
Dim eh As Double

' Define the target width for the image
ew = 396

' Get the current width and height of the selected image
w = Selection.InlineShapes(1).Width
h = Selection.InlineShapes(1).Height

' Variable to store percentage for resizing
Dim percentage As Double
percentage = 1

' If the image width exceeds the target width, calculate the new height
If (w > ew) Then
    percentage = ew / w
    eh = h * percentage
End If

' Set the new width and height for the image
Selection.InlineShapes(1).Height = eh
Selection.InlineShapes(1).Width = ew
End Sub

Explanation:

How to Use:

  1. Open Microsoft Word and press Alt + F11 to open the VBA editor.

  2. In the editor, go to Insert > Module and paste the above macro code.

  3. Close the editor and run the macro whenever you want to resize an image inserted into the Word document.


Previous Post
Run VS as Admin
Next Post
Internet Speed