Search results

Word Macro for Resizing Images that Have a Specific Style

by Tom Johnson on Aug 9, 2008
categories: technical-writing

When you single source from an online help authoring tool and generate an output to Microsoft Word, almost invariably you have some clean-up reformatting to do. For me, one of these areas deals with screenshot images.

I prefer to have Word resize my screenshots (to a smaller size) because images look a lot sharper and crisper when Word resizes them rather than when SnagIt or Photoshop resizes them (even with smooth scaling selected).

Whatever your cleanup process, you might find the following image resizing macro helpful. It only resizes images that have a specific style (p_Result) before the image. It resizes the image to 75% of its original size.

Note: It's important to isolate images that are surrounded by a specific style because you don't want to resize all your images. You don't want your note, tip, caution, and button images shrunk to 75% of their original size. Also, your substep images may need to have smaller sizes than your regular image sizes.

Here's the macro:

Sub ImageResize()
Dim PercentSize As Integer
Dim MyStyle As String
Dim oIshp As InlineShape
Dim oshp As Shape
PercentSize = InputBox("Enter percent of full size", "ResizePicture ", 75)
MyStyle = "p_Result"
With ActiveDocument
For Each oIshp In .InlineShapes
With oIshp
If .Range.Paragraphs(1).Style = MyStyle Then
.ScaleHeight = PercentSize
.ScaleWidth = PercentSize
End If
End With
Next oIshp
For Each oshp In .Shapes
With oshp
If .Anchor.Paragraphs(1).Style = MyStyle Then
.ScaleHeight Factor:=(PercentSize / 100), _
RelativeToOriginalSize:=msoCTrue
.ScaleWidth Factor:=(PercentSize / 100), _
RelativeToOriginalSize:=msoCTrue
End If
End With
Next oshp
End With
End Sub

If you have no idea how to integrate a macro into your Word document, follow these steps. (This applies to Word 2007.)

  1. Click the Developer tab, and then click the Macros button.
  2. Type a name for the macro, such as ImageResize, and then click Create.
  3. Highlight the code that starts with Sub ImageResize and ends with End Sub.
  4. Paste the sample code above in its place, and then click Save and close the macro window.

To run the macro, first make sure your images have a p_Result style before them. Then do the following:

  1. Click the Developer tab, and then click the Macros button.
  2. Select the ImageResize macro, and click the Run button.

About Tom Johnson

Tom Johnson

I'm an API technical writer based in the Seattle area. On this blog, I write about topics related to technical writing and communication — such as software documentation, API documentation, AI, information architecture, content strategy, writing processes, plain language, tech comm careers, and more. Check out my API documentation course if you're looking for more info about documenting APIs. Or see my posts on AI and AI course section for more on the latest in AI and tech comm.

If you're a technical writer and want to keep on top of the latest trends in the tech comm, be sure to subscribe to email updates below. You can also learn more about me or contact me. Finally, note that the opinions I express on my blog are my own points of view, not that of my employer.