+ Reply to Thread
Results 1 to 11 of 11

Cannot Copy Image with Varying URL from Webpage

  1. #1
    Registered User
    Join Date
    07-01-2011
    Location
    Boston, mass
    MS-Off Ver
    Excel 2007
    Posts
    7

    Question Cannot Copy Image with Varying URL from Webpage

    Hi there, ive been looking all over the internet for answers to my problem but could find none.

    I need to be able to copy a specific graph, in the form of an image, from a web page. This image always has the same name, "itmu-cpu-generic-lastweek." I already have to code to create an instance of internet explorer and go to the page, but cannot find how to copy that one image and not the whole web page.

    I guess it does not really matter if it is copied to the clipboard or saved to the computer, as long as it is on my computer so that excel may grab it and throw it into a cell. Any help will be greatly appreciated
    Last edited by kalt; 07-06-2011 at 05:16 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: You are subscribed to this thread Copying a picture from a web page and pasting i

    Hello kalt,

    Welcome to the Forum!

    You don't need to Internet explore to do this. This macro will down a picture from a website provided you know the path. You can get the path by right clicking on the picture and clicking copy image location. It also lets you choose where to save the file. Copy this code into a separate VBA module in your workbook.
    Please Login or Register  to view this content.


    Demonstration routine, downloads an image from Excel Forum to the C: drive
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-01-2011
    Location
    Boston, mass
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: You are subscribed to this thread Copying a picture from a web page and pasting i

    Sorry for the late reply, I have been away from a computer for some time. I apologize royUK, if you could change the thread title to "Cannot Copy Image with Varying URL from Webpage"

    Thanks Leith Ross for your reply, and I should have mentioned this above but the URL of the image is constantly different, which is what is giving me problems. I can get to the web page with no problem, but after that all I have to go by is the name of the image, "itmu-cpu-generic-lastweek" as it is labeled on the page and in the HTML. Any suggestions?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: You are subscribed to this thread Copying a picture from a web page and pasting i

    Hello kalt,

    Can you post the URL? I can then have a look at the page source and better answer your question.

  5. #5
    Registered User
    Join Date
    07-01-2011
    Location
    Boston, mass
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Cannot Copy Image with Varying URL from Webpage

    Sure thing Leith but unfortunately you would not be able to reach the site as it is only accessible internally at my work. I can paste the sections of the page source that are relevant, let me know if you need more.

    HTML Code: 

  6. #6
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Cannot Copy Image with Varying URL from Webpage

    Loop through HTMLDocument.images, looking for the image with the specified .alt property, and get its URL from the .src property. Then use Insert - Picture - From File - the URL, in Excel's Macro Recorder to generate the VBA code to download the image and insert it into a cell.

  7. #7
    Registered User
    Join Date
    07-01-2011
    Location
    Boston, mass
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Cannot Copy Image with Varying URL from Webpage

    Quote Originally Posted by Chippy View Post
    Loop through HTMLDocument.images, looking for the image with the specified .alt property, and get its URL from the .src property. Then use Insert - Picture - From File - the URL, in Excel's Macro Recorder to generate the VBA code to download the image and insert it into a cell.

    Thanks Chippy, this looks like it could be exactly what I have been looking for. Only thing though: I'm not very good with html :/ . Could you provide a short example of what the code might look like?

    I'll try tinkering around with it in the meantime.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Cannot Copy Image with Varying URL from Webpage

    Hello kalt,

    Here is an example macro using the call to download the picture to a file. You will need to change the URL, the FilePath, and the Alt property of the picture to what you need.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 07-06-2011 at 03:34 PM.

  9. #9
    Registered User
    Join Date
    07-01-2011
    Location
    Boston, mass
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Cannot Copy Image with Varying URL from Webpage

    Thanks Leith, this code looks perfect. I'll give it a shot with rest of the code above.
    Last edited by kalt; 07-06-2011 at 04:19 PM.

  10. #10
    Registered User
    Join Date
    07-01-2011
    Location
    Boston, mass
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Cannot Copy Image with Varying URL from Webpage

    Ok so I took the

    Please Login or Register  to view this content.

    of your code and threw in my part

    Please Login or Register  to view this content.
    instead of saving to the computer and I'm happy to say that it worked perfectly. Thank you so much Chippy for the idea and Leith for that excellent code

  11. #11
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Cannot Copy Image with Varying URL from Webpage

    Now please do the decent thing and post a link to this thread in your* cross-posted threads in other forums (i.e.. vbaexpress, ozgrid and several others), saying that your question has been solved and so people don't waste time working on it.

    http://www.ozgrid.com/forum/showthread.php?t=155655
    http://www.vbaexpress.com/forum/showthread.php?t=38086

    *Unless I'm mistaken and by an amazing coincidence at least 2 different people have posted the same problem with the same wording on the same date on different forums
    Last edited by Chippy; 07-07-2011 at 12:28 PM.

+ 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