How to Use Excel VBA to Insert and Save Images from File Paths
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.

- 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.
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.
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.
Press 'Alt + F11' in your Excel workbook to open the Visual Basic for Applications (VBA) editor.
Click on 'Insert' in the top menu and select 'Module' to create a blank script window.
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).
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 (\).
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.

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. Download the Installer: Visit the official WPS Office website and click the free download button.
- 2. Install WPS Office: Run the downloaded installer and follow the on-screen prompts to set up the software.
- 3. Open Your Spreadsheets: Launch WPS Spreadsheet and open your existing Excel files directly without losing any formatting.

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.




