VBA & Macro Problems

How to Use Excel VBA to Insert and Save Images from File Paths

Kushani NimanthikaKushani Nimanthika Nov 11, 2026 869 views

Question details

The user needs to automate the process of inserting images into a worksheet using file paths and saving them with specific names using Excel VBA.

How to Use Excel VBA to Insert and Save Images from File Paths
Product
Excel
Device & OS
not provided
Scenario
Automating image insertion and exporting via VBA macros.
Observed behavior
Images need to be inserted from paths in column A and exported or saved as JPG files using names specified in column B.
Before you start

Ensure that the Developer tab is enabled in your Excel ribbon and that your workbook is saved as a Macro-Enabled Workbook (.xlsm) to run VBA code successfully.

Solution 1Recommended

Use VBA to Insert Images from Paths and Save via Temporary Chart

Run a VBA script that loops through the image paths in Column A, inserts them into the sheet, and uses a temporary chart object to export them as JPGs with names from Column B.

This method uses an automation loop to read the file paths from your spreadsheet, places the image onto the worksheet, and then copies it into a temporary chart object. The chart object's export method is then utilized to save the picture out to your specified destination folder.

Make sure your target folder exists on your computer before running the script, as VBA cannot save to a non-existent directory.

1
Open the VBA Editor

Press 'Alt + F11' in your Excel workbook to open the Visual Basic for Applications (VBA) editor.

2
Insert a New Module

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

3
Prepare Your Data

In 'Sheet1', list your image file paths in Column A (e.g., C:\Images\pic1.jpg) and the desired output file names in Column B (e.g., NewPic1).

4
Paste and Customize the VBA Code

Paste your VBA subroutines into the module. Update the 'savePath' variable in the code to point to your actual destination folder, ensuring it ends with a backslash (\).

5
Run the Macro

Click anywhere inside the main subroutine and press 'F5' or click the 'Run' button. A message box will appear once the images are successfully inserted and saved.

Use VBA to Insert Images from Paths and Save via Temporary Chart
Temporary Chart Object: The script creates a temporary chart to bypass Excel's limitations on directly exporting picture objects. The chart is deleted automatically after the export is complete.
Free Microsoft Office alternative

Looking for a Lightweight Spreadsheet Tool? Try WPS Office

If you frequently work with Excel macros, VBA, and complex spreadsheet tasks, WPS Office offers a highly compatible, lightweight, and free alternative. It supports Microsoft Office file formats seamlessly and provides a familiar interface so you can migrate without a learning curve.

  1. 1. Download the Installer: Visit the official WPS Office website and click the free download button.
  2. 2. Install WPS Office: Run the downloaded installer and follow the on-screen prompts to set up the software.
  3. 3. Open Your Spreadsheets: Launch WPS Spreadsheet and open your existing Excel files directly without losing any formatting.
Fully compatible with Microsoft Excel formats (.xlsx, .xlsm, .csv).Familiar user interface makes transitioning effortless.Lightweight software that runs smoothly on older devices.Advanced spreadsheet features for data analysis and visualization.
microsoft office alternative - wps office

Frequently Asked Questions

Why is the VBA macro returning a 'File not found' error?

This usually happens if the file paths listed in Column A are incorrect, or if the images have been moved or deleted. Double-check that the full path, including the drive letter and file extension (e.g., C:\folder\image.jpg), is accurate.

Can I save the exported images in PNG format instead of JPG?

Yes. In the export subroutine, change the FilterName parameter to "PNG", and update the file extension string in the main loop from ".jpg" to ".png".

Why is my exported image coming out blank or cut off?

This can occur if the temporary chart object isn't sized perfectly to the image, or if the screen updates interrupt the paste process. Adding a 'DoEvents' command after pasting the image into the chart can sometimes resolve clipboard timing issues in VBA.

Do I need to enable macros every time I open the workbook?

If you save your workbook as an Excel Macro-Enabled Workbook (.xlsm), you may still see a security warning when opening it. You can click 'Enable Content' or adjust your Trust Center settings in Excel to allow macros to run automatically from trusted locations.