PDA

View Full Version : Copying a picture from a web page and pasting into Excel



sam3444
07-01-2011, 09:27 AM
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 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 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 :)

Kenneth Hobs
07-01-2011, 10:24 AM
Welcome to the forum!

Your post does not contain enough information for us to give specific help. We need to know the web page url and other details like inputs on the web page at the very least. Usually, you should post your code between vba tags so that we have a starting point or even a simplified file.

For the graph, if it were a single image file as you say, we could copy that. If it is generated by a javascript, a partial screenprint will be your only option. To do a partial screen print, a 3rd party program will be needed possibly.

As for throwing the image into a cell, that can't be done. We can put a corner in the top left of a cell. Size may an issue as well.

It sounds like something like what I did in the following thread would help. http://www.vbaexpress.com/forum/showthread.php?t=34206

sam3444
07-06-2011, 08:27 AM
Sorry for the late reply, I have been away from a computer for some time.

Thanks Kenneth 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.

My code essentially opens an instance of Internet Explorer and navigates to the Web page, whose URL is always the same. I can copy the whole page to the clipboard with no problem but that becomes a mess when pasted into excel. So, to get around this, I have tried navigating to the URL of the image and using the same "Copy the Whole Page" in the form of

Dim dat As DataObject
Set dat = New DataObject

dat.SetText ie.Document.DocumentElement.innerhtml
but the URL changes constantly as I mentioned above, so it did not work. So I have been trying to play around with that line of code above to just get the specific image, but with no luck. Any suggestions?

Kenneth Hobs
07-07-2011, 08:30 AM
Since I don't know the details, it is hard to advise. To program, you need to know the logic. Many sites use a naming convention for image files that is easily programmed.