How to Dynamically Crop Charts from Screenshots Using VBA
Question details
The user wants to use VBA to dynamically crop charts from screenshots because fixed pixel coordinates fail when screen resolution or aspect ratio changes.

- Product
- Presentation
- Device & OS
- not provided
- Scenario
- Automating the extraction of specific charts from inserted screenshots without using hardcoded crop dimensions that break across different devices.
- Observed behavior
- Fixed crop coordinates in VBA work for a single screen size but crop the wrong areas when the display resolution or scaling settings change.
Ensure the Developer tab is enabled in your presentation software to access the VBA editor, and verify that the screenshots are already inserted into your active slide.
Use Boundary Markers for Dynamic VBA Cropping
Add consistent visual markers or standardized capture area ratios to your charts before taking screenshots so VBA can calculate boundaries dynamically.
Relying on fixed coordinates often fails because display scaling and resolutions vary widely. By adding a recognizable marker (like a distinct colored border) or maintaining a strict capture ratio, you can write a VBA script that calculates crop boundaries based on the shape's relative dimensions rather than absolute points.
Before capturing the chart from the source application (such as Power BI or Excel), add a distinct border or ensure the screenshot tool captures an exact aspect ratio every time.
Paste or insert the captured screenshot into your slide.
Press ALT + F11 to open the VBA Editor, then insert a new Module from the Insert menu.
Write your macro to select the image shape. Instead of fixed numbers, use formulas based on the image's total width and height (e.g., Shape.Width * 0.1) to define variables for the crop margins.
Apply the calculated variables to the PictureFormat properties: CropLeft, CropRight, CropTop, and CropBottom, then run the macro.

Use WPS Presentation to Automate Image Formatting
WPS Office provides robust VBA support, allowing you to seamlessly run macros for cropping images, formatting slides, and automating repetitive presentation tasks.
- 1. Download WPS Office: Download and install WPS Office from the official website.
- 2. Open your presentation: Launch WPS Presentation and open your document containing the screenshots.
- 3. Access the VBA Editor: Navigate to the Tools tab and click on the Macro or VBA Editor button.
- 4. Run your macro: Paste your dynamic cropping VBA code into a new module and execute it to format your slide images.

Frequently Asked Questions
Why do my VBA crop coordinates change on different computers?
Fixed VBA crop coordinates depend on screen resolution, display scaling (DPI), and aspect ratios. If these settings vary between computers, the absolute pixel coordinates will not align with the target image area.
Can VBA natively scan an image to find a specific color marker?
No, native VBA does not have a built-in function to scan image files for specific pixel colors. You must use external libraries or Windows API calls (like GetPixel) to analyze colors on the screen.
Is there a way to crop an image by percentage rather than exact points in VBA?
Yes. You can calculate crop values dynamically by multiplying the Shape.Width and Shape.Height properties by a specific percentage decimal, then applying those calculated values to the PictureFormat.Crop properties.




