How to Use VBA to Insert and Resize Pictures in Excel Cells
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.

- 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.
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.
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.
Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.
Click 'Insert' from the top menu and select 'Module' to create a blank script window.
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.
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\).
Close the VBA editor, return to your worksheet, and press Alt + F8. Select your new macro and click 'Run'.

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. Open your file in WPS: Launch WPS Spreadsheet and open your .xlsm or .xlsx file containing the image names.
- 2. Access the Developer Tools: Navigate to the Developer tab on the ribbon to access the Macro and VBA Editor.
- 3. Run your Script: Click on Macros, select your picture-inserting macro, and click Run to automatically fetch and resize your images.
- 4. Save your Workbook: Save your progress to retain the newly inserted 120x120 pictures inside your spreadsheet safely.

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.




