Macro to crop and resize images in Word(macOS)

Preface

This article is mostly intended for users of Ekahau Site Survey Pro generating report documentation.

I encourage you to clean-up, manipulate and prepare your floor plans before importing them into Ekahau. This will save you from a headache when it comes to report-writing time. Image manipulation is much easier before we create the Ekahau project.

However…

Main Attraction

We have all been there… right?

The survey is complete, we have looked through and analysed the collected data. It’s time to smash out that report document, only, the coverage map visualisations have a ton of white space surrounding them and the floor plan is minuscule in the centre of the page.

It’s a PITA, but, by creating a macro within Word we can automate (and dramatically speed up) the image cropping and resize actions.

  1. Create and run your Ekahau report template
  2. Word > Preferences
    Change measurement unit to points
  3. Tools > Macro > Visual Basic Editor
    double click “This Document”
    copy and paste the VBA script below

    Sub CropAndResize()
    ' This macro crops and resizes images
    ' The units are 'points'
    Dim oILS As InlineShape
    Set oILS = Selection.InlineShapes(1)
    With oILS
    .PictureFormat.CropLeft = 100
    .PictureFormat.CropTop = 100
    .PictureFormat.CropRight = 100
    .PictureFormat.CropBottom = 100
    End With
    With oILS
    .LockAspectRatio = True
    ' .Height = 260
    ' .Width = 450
    End With
    lbl_Exit:
    Exit Sub
    End Sub
  4. Click “Save” in the top-left
  5. You will likely get an error message, cancel
  6. Save the Document / Macro in the special “.docm” format
  7. Next, create a shortcut for the macro
    Tools > Customise Keyboard
  8. Assign a keyboard combo of your choosing
  9. Test the macro on an image
  10. The crop values are absolute! Running the macro a second time will not affect the image cumulatively.
  11. Tools > Macro > Visual Basic Editor
    Make the changes
    Save in the top left
    Close the window
  12. Run the macro again using your shortcut
  13. The macro can also be used to resize the image
    To define the width or height using the macro, remove the apostrophe ‘ from the appropriate line width or height and set the value in points
  14. If you are unsure what the point value should be, consider
    cropping an image using the macro
    resize the image manually within Word
    select the “Picture Format” within the ribbon
    take note of the width or height
    enter the value into the macro and run again

The macro will need to be applied to each image that requires manipulation, depending on your project, you may need to alter the macro for different shape floors within your report output.

When designing your report template, you can use the visualisation tag:

<#"visualization": {"resolution-width": "-1"}#>

This tag sets the resolution of the rendered visualization. This time the unit is in pixels. This tag is often used to reduce the resolution and save space in the resulting generated report…
That is NOT what we are doing here, set to negative 1, to force use the original resolution of the map image.

This should allow you to crop and enlarge the image within Word without it becoming grainy.

If you are working on Windows, I suggest this version of the article:
Macro to crop and resize images in Word(Windows)

Credit goes to Numerous Google search results for this solution, including this forum post

I hope you found these instructions reasonably easy to follow, if you did? Great, let me know. Twitter: @nickjvturner
If not, please comment below with recommendations.

One thought on “Macro to crop and resize images in Word(macOS)

  1. Pingback: Macro to crop and resize images in Word(Windows) | WLANs, Wi-Fi & Technical musings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s