Results 1 to 17 of 17

Thread: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA macro

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    10

    [Resolved] Automatically save all pictures shown in Internet Explorer using VBA macro

    Hello,

    I am using a Excel VBA macro to control the Internet Explorer (IE = CreateObject("InternetExplorer.Application") ... IE.Navigate ...). Now I would like to save to hard disk all pictures that are currently visible on the IE, WITHOUT navigating again to a special picture-URL (so I cannot use html parsing or Wget-Tools). How to do that?

    Many Thanks,
    Ursula
    Last edited by ursulala; Mar 17th, 2010 at 12:23 PM. Reason: resolved

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Automatically save all pictures shown in Internet Explorer using VBA macro

    Thread moved from "VB6" forum to 'Office Development/VBA' forum

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Automatically save all pictures shown in Internet Explorer using VBA macro

    there is a recent thread, last few months, (or more than one) in the vb6 forum to do exactly this (from a webbrowser control i think), i believe it would still all work in vba, but you will need to do a search to find the thread, i did have some input in the thread
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    10

    Re: Automatically save all pictures shown in Internet Explorer using VBA macro

    Thank a lot, I see that DragonBay for example had the same problem as I. I will go through that tomorrow as here in Europe it is already late in the evening. I will let you know if problem is fixed.
    Good night, Ursula

  5. #5
    Addicted Member
    Join Date
    Jul 2009
    Posts
    208

    Re: Automatically save all pictures shown in Internet Explorer using VBA macro

    Get the collection of HTML image elements using GetElementsByTagName("IMG"), then use URLDownloadToFile to download each one. The former function is part of the MS HTML Object library.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Automatically save all pictures shown in Internet Explorer using VBA macro

    I see that DragonBay for example
    i believe that was the tread i was thinking of
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    10

    Re: Automatically save all pictures shown in Internet Explorer using VBA macro

    I think, it's not a solution to use URLDownloadToFile since I don't know it's url and it's not stored on the server.

    The problem with this image is that it's url is not fixed and it can't be requested for twice from the server cause it's generated automatically every time (it is a validation picture),
    so the server doesn't hold a copy of this image...

    DragonBoy described the same problem in VB6 forum, I will go through the staff and see whether DragonBoy got a solution.

    DragonBoy has already described the same problem in VB6 forum, I will go through the staff and see whether DragonBoy got a solution.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Automatically save all pictures shown in Internet Explorer using VBA macro

    And how to do this if verification img does not have a name:

    <img src="/sw/verification/verif.php?c=login" alt="captcha" class="captcha"/>

    Thanx a lot !
    i decided to answer this in your own thread
    loop through all the images to find the one with some correct value

    vb Code:
    1. for each ele in wb.document.getelementsbytagname("img")
    2.   if instr(ele.innerhtml, "alt=""captcha""") > 0 then exit for
    3. next
    4. 'ele i now an object of that specific image
    it may be possible that alt is a property of the image, then you could just use
    if ele.alt.value = "captcha" then exit for
    but i was not sure so used instr
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    10

    Re: Automatically save all pictures shown in Internet Explorer using VBA macro

    Thanks to all of you, especially to westconn1 !
    I use ele.getAttribute("src") instead of ele.innerhtml since the result of innerhtml always was empty. I suppose img is not really a full tag with open and close. Now it works relatively fine, only some fine tuning is still necessary.
    Ursula

  10. #10
    New Member
    Join Date
    Jan 2011
    Posts
    3

    Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m

    Give you a more simple example. I use msinet to get source form website and after that prasing it
    You add
    a command button ( and add this following code )
    a inet named inet1
    a textbox named text1
    a listview named lv
    Code:
       
        Dim d As Integer
        Dim a As String
        Dim b() As String
        Dim c As Integer
        lv.Clear 
    
        a = Inet1.OpenURL(Text1.Text)
        b = Split(a, "img src=")
        For c = 1 To UBound(b)
    
                    lv.ItemAdd lv.Count + 1, spt(b(c), """", """")
    
        Next c
    
        lv.ColumnAutosize 1, caItem
        Clipboard.Clear
        Timer1.Enabled = True
    
    
    
    End Function
    
    Function spt(str As String, a As String, b As String)
        On Error Resume Next
        Dim a1() As String
        Dim a2() As String
        a1 = Split(str, a)
        a2 = Split(a1(1), b)
        spt = a2(0)
    End Function
    I wrote this code in notepad ( I don't have vb6 on my computer ) so it may have some problems. You can modify to suit your purpose
    ( Sorry for my poor english )

  11. #11
    New Member
    Join Date
    Jul 2011
    Posts
    4

    Re: Automatically save all pictures shown in Internet Explorer using VBA macro

    Quote Originally Posted by westconn1 View Post
    i decided to answer this in your own thread
    loop through all the images to find the one with some correct value

    vb Code:
    1. for each ele in wb.document.getelementsbytagname("img")
    2.   if instr(ele.innerhtml, "alt=""captcha""") > 0 then exit for
    3. next
    4. 'ele i now an object of that specific image
    it may be possible that alt is a property of the image, then you could just use
    if ele.alt.value = "captcha" then exit for
    but i was not sure so used instr
    Welcome everybody!
    Sorry for digging it up again but Your post was actually the only one that seems to help resolving this problem. I'm struggling on 2 other forums now and try to explain the problem, but no one seems to understand even a bit.
    My question is: what actually is returned by this function in varieable "ele"? I think it's something like this:
    Code:
    ele = <img src="someWWW" alt=captcha"/>
    . What code (method, function) let me save it as an image?

    Thank You for any help..

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m

    My question is: what actually is returned by this function in varieable "ele"
    an object containing the html element from the webpage, with its properties and methods

    What code (method, function) let me save it as an image?
    if you have the src url from the element, you can use urldownloaedtofile API to save the src to disk
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13
    New Member
    Join Date
    Jul 2011
    Posts
    4

    Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m

    Thank You for answer!
    And will this method save picture that's allready loaded in browser? Because reloading it will completly change the picture...

  14. #14
    New Member
    Join Date
    Jul 2011
    Posts
    4

    Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m

    Well, if it can't be saved from IE tamplate maybe it can be save by prinscreen'ing whole site and cropping it to size of disered image? What do you think?

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m

    probably trying to beat captchas, would be against the acceptable use policy of this site
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  16. #16
    New Member
    Join Date
    Jul 2011
    Posts
    4

    Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m

    Well, probably yes, but I'm not the one who has started this topic anyway Apart from that, no one wants to beat captcha, it is in educational purposes only..

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Resolved] Automatically save all pictures shown in Internet Explorer using VBA m

    you should be able to copy the picture to clipboard, then save to file

    you could try the execwb method of the internet explorer instance to copy the image
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width