logo
search
VBA & Macro Problems

How to Use VBA to Insert and Resize Pictures in Excel Cells

Aamir Naveed AkramAamir Naveed Akram Oct 14, 2026 870 views

Question details

The user wants to automate the process of finding images in a specific folder based on file names in column A, inserting them into column B, and resizing them to a fixed size of 120 by 120 pixels.

How to Use a VBA Macro to Insert and Resize Pictures in Excel Cells
Product
Excel
Device & OS
not provided
Scenario
Automating bulk image insertion and formatting in spreadsheets using VBA macros.
Observed behavior
Images need to be automatically fetched from a local directory, placed into adjacent matching rows, and resized to precise pixel dimensions without manual adjustment.
Before you start

Ensure the Developer tab is enabled in your Excel ribbon and verify the exact folder path where your target images are stored before running any VBA code.

Solution 1Recommended

Create and Run a Picture Insertion Macro

Use a custom VBA script to loop through column A, locate the images, insert them into column B, and format their size.

This macro utilizes a loop to read file names from the first column, verifies if the file exists in the specified directory, and then uses the Pictures.Insert method. Finally, it adjusts the Shape properties to match the required 120x120 pixel dimensions.

1
Open the VBA Editor

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

2
Insert a New Module

Click 'Insert' from the top menu and select 'Module' to create a blank script window.

3
Add the Macro Code

Paste your VBA script designed to loop through cells. Ensure the code sets the picture's Width and Height properties to 120 and turns off the aspect ratio lock (msoFalse) if exact dimensions are needed.

4
Update the Folder Path

In your pasted code, locate the folderPath variable and update it with the exact directory path where your images are saved, ensuring it ends with a backslash (e.g., C:\Images\).

5
Run the Macro

Close the VBA editor, return to your worksheet, and press Alt + F8. Select your new macro and click 'Run'.

Create and Run a Picture Insertion Macro
Troubleshooting Empty Results: If the macro produces no result, double-check that the folder path is 100% correct and that the file names in Column A include the exact file extensions (like .jpg or .png) matching the actual files.

Automate Tasks with Macros in WPS Spreadsheet

WPS Office provides robust support for Excel files and VBA macros, allowing you to run your existing picture-insertion scripts seamlessly and manage bulk image tasks efficiently.

  1. 1. Open your file in WPS: Launch WPS Spreadsheet and open your .xlsm or .xlsx file containing the image names.
  2. 2. Access the Developer Tools: Navigate to the Developer tab on the ribbon to access the Macro and VBA Editor.
  3. 3. Run your Script: Click on Macros, select your picture-inserting macro, and click Run to automatically fetch and resize your images.
  4. 4. Save your Workbook: Save your progress to retain the newly inserted 120x120 pictures inside your spreadsheet safely.
Fully compatible with Microsoft Excel (.xlsx, .xlsm) formats.Supports VBA macros for advanced spreadsheet automation.Lightweight and fast, even with large datasets and multiple inserted images.
microsoft office alternative - wps office

Frequently Asked Questions

Why did my macro run but no pictures were inserted?

This usually happens if the folder path in the VBA code is incorrect, missing a trailing backslash, or if the file names listed in column A don't include the correct file extensions (like .jpg or .png).

How do I lock the aspect ratio when resizing pictures via VBA?

In your VBA script, set the ShapeRange.LockAspectRatio property to msoTrue. This ensures the image doesn't distort, though it might prevent the picture from hitting exactly 120x120 pixels on both sides.

Can I insert pictures directly into cells so they move with the cells?

Yes, by setting the inserted picture's Placement property to xlMoveAndSize (or 1) in your VBA code, the image will automatically move and resize if the underlying cell's width or height changes.