Forum Discussion
Create a macro to crop images
- Feb 20, 2022
seanmccole The information on using those properties is pretty sparse, but after a few attempts, I believe the applicable property is the .PictureFormat.Crop.PictureOffsetX and that the offset is from the center of the picture. For the result that you want, probably no offset is required.
Using the following code with an image that was distorted to the size of your image:
With ActiveDocument
For i = 1 To .InlineShapes.Count
With .InlineShapes(i)
.PictureFormat.Crop.ShapeWidth = .Height
.PictureFormat.Crop.ShapeHeight = .Height
.PictureFormat.Crop.PictureOffsetY = 0
.PictureFormat.Crop.PictureOffsetX = 0
End With
Next i
End Withthe result shown compared to an uncropped version of the image
Increasing the offset, by using
.PictureFormat.Crop.PictureOffsetX = 10
reduces the crop from the left
and reducing it by using
.PictureFormat.Crop.PictureOffsetX = -10
increases the crop from the left
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.
Create and run your Ekahau report template
Word > Preferences
Change measurement unit to points
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
Click "Save" in the top-left
You will likely get an error message, cancel
Save the Document / Macro in the special ".docm" format
Next, create a shortcut for the macro
Tools > Customise Keyboard
Assign a keyboard combo of your choosing
Test the macro on an image
The crop values are absolute! Running the macro a second time will not affect the image cumulatively.
Tools > Macro > Visual Basic Editor
Make the changes
Save in the top left
Close the window
Run the macro again using your shortcut
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
If you are unsure what the point value should be, consider the following
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.
Windows Users
Create and run your Ekahau report template
File > Options > Advanced > Display
Change:
Show measurements in units of to: Points
OK
(In the Ribbon) View > Macros > View Macros
Type "CropAndResize" into the Macro Name field
Click "Create"
We are now in the MSWord Visual Basic Editor
Copy and paste the VBA script below in the editor in between the lines of Sub "CropAndResize" and "EndSub"
Commented out lines within VBA scripts begin with ‘'’
' 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
Click "Save" in the top-left
You may get an error message, click "cancel"
Save the Document / Macro into the special ".docm" format
Once the macro is saved and we are returned to looking at the Word document
Create a shortcut for the macro
File > Options > Customise Ribbon
At the bottom of the screen select Keyboard Shortcuts "Customise"
Scroll down through the categories (on the left) to Macros
Make sure the Macro Name is visible and selected in your Macros box (on the right)
Assign a keyboard combo of your choosing in ‘Press new shortcut key:’
Click "Assign"
Then you can close the Options windows
Test the macro on an image
by selecting the image and using the newly created keyboard shortcut
Please Note: The crop values used by this macro are absolute! Running the macro a second time will not affect the image cumulatively.
If the crop amount is not sufficient, we need to go back to the macro and make some changes.
(In the Ribbon) View > Macros > View Macros
Edit
This time, all we need to do is alter the crop values
Once complete
Save in the top left
Close the window
Run the macro again using your shortcut .for more information you can visit here https://protrackinghub.com/