+ Reply to Thread
Results 1 to 1 of 1

Use VBA to download a dynamically generated image from the web.

  1. #1
    Registered User
    Join Date
    07-01-2012
    Location
    Spain
    MS-Off Ver
    Excel 2007
    Posts
    1

    Use VBA to download a dynamically generated image from the web.

    Hi.

    I'm using a certain web service which generates png images dynamically using a cgi script. I need to save those images to my hard drive.

    Right now I'm using an excel script which loads said webpage using InternetExplorer object, and I'm able to set properties I need by calling the needed JavaScript functions provided, by using document.parentWindow.execScript(). The image then is generated correctly.

    The problem is, I can't find the way to automatically save the image using the methods I found on the internet so far. Said CGI script only renders images if the "referrer" is set to the generator main page. So far I've been able to get my VBA script to retrieve the correct URLs for the images I needed (something along the lines of "render.cgi?key1=val1&key2=val2&key3=val3...), but since the referrer field is enforced, it's of no use afterwards.

    What I've been doing so far is set a breakpoint on the script after the image generation scripts on the page have been called, and save the image manually by using right click - "save image as..." on the internet explorer window. Then, continue looping through the image parameters. However there are several hundreds of such images I need to retrieve, saving all them manually is tedious.

    Is there a way to save an image automatically? Hope my explanation is not very cryptic. I've been thinking of two possibilities so far (maybe there are some better ways?):
    • API call to Internet Explorer to save the image, passing the image name and path parameters.
    • Forge a HTTP request with a spoofed Referrer field to retrieve an image directly.

    I have very little experience on working with Internet from within Excel so any help is appreciated.

    Regards, Bob.

    EDIT:

    After some reaserch, I've been able to adapt the class provided here http://www.lazerwire.com/2011/11/exc...-internet.html to send a "Referer" header along with an http request, and receive a neatly generated images. However, apparently, I can't save files with unicode characters from within VBA, will look into it.
    Last edited by nponoBegHuk; 07-01-2012 at 12:57 PM. Reason: Solution found

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1