How to Download Images from a URL Using VBA in Spreadsheets
Question details
The user needs a way to download images from a URL when a file opens without permanently embedding the images into the document.

- Product
- Spreadsheets
- Device & OS
- not provided
- Scenario
- Automating document opening to load external images dynamically via a macro script.
- Observed behavior
- Requires specific VBA code to fetch and insert images dynamically via URL without increasing the document file size.
Ensure that you have enabled Developer tools and macros in your spreadsheet application before adding or running VBA code. Verify that the target image URLs are publicly accessible.
Use VBA Shapes.AddPicture Method
Use the built-in AddPicture method to link an image from a URL dynamically without saving it permanently in the document.
This approach uses standard VBA methods to link a picture via URL.
If your URL requires authentication, this simple method may not work, and you might need an API-based solution.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor.
Click on 'Insert' in the top menu and select 'Module' to create a blank script.
Write a script using ActiveSheet.Shapes.AddPicture(URL, msoTrue, msoFalse, Left, Top, Width, Height). Setting the second parameter to msoTrue (LinkToFile) and the third to msoFalse (SaveWithDocument) ensures the image is not permanently embedded.
Call this macro from the Workbook_Open event in the ThisWorkbook module so the image loads automatically every time the file is opened.

Run VBA Macros Seamlessly with WPS Office
WPS Office provides robust support for VBA macros, allowing you to run complex automation scripts like downloading images from URLs just as you would in other major spreadsheet software.
- 1. Install WPS Office: Download and install the latest version of WPS Office.
- 2. Enable Developer Tools: Open your spreadsheet, navigate to the Developer tab, and ensure macros are enabled.
- 3. Open the VBA Editor: Click on 'VBA Editor' or press ALT+F11 to access the coding environment.
- 4. Run Your Script: Paste your dynamic image loading code and run the macro to see the results.

Frequently Asked Questions
Why are my downloaded images permanently saved in the file?
If using the Shapes.AddPicture method, ensure the SaveWithDocument parameter is strictly set to msoFalse and LinkToFile is set to msoTrue.
Can I download images from secure HTTPS URLs using VBA?
Yes, but secure URLs that require authentication or specific headers might need advanced API methods like XMLHTTP instead of basic picture insertion.
Where can I get help if my VBA code throws an error?
For advanced troubleshooting, reviewing the Office VBA documentation or searching Stack Overflow with the 'vba' tag is highly recommended by developers.




