Results 1 to 4 of 4

Download/Save webpage images to file using VBA

Threaded View

  1. #1
    Registered User
    Join Date
    06-04-2007
    MS-Off Ver
    Excel 2007
    Posts
    94

    Download/Save webpage images to file using VBA

    I had originally asked for a response to this question over at MrExcel Board, some days ago but the solution does not seem to fix the problem. I was hoping maybe someone here could shed some light on getting this macro to work.

    I tried using the following

    Option Explicit
    
    Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    Sub GetPageTitle()
        Dim i As Long, url As String
        For i = 1 To 4
            DoEvents
            url = "http://capnhud.host22.com/examples/" & Sheet1.Range("A" & i).Value & ".jpg"
            URLDownloadToFile 0, url, "C:\Documents and Settings\Owner\Desktop\media\download\" & Sheet1.Range("A" & i).Value & ".jpg", 0, 0
        Next
    End Sub
    to get these files which are listed in the A column in a new workbook with the sheet being Sheet1

    117427934569752sm
    117428128343967sm
    117428291462196sm
    117428380391871sm

    and the only thing that has ever showed up was a .jpg file with no name and with no preview.

    Is there something that I am missing to get this to work?

    UPDATE:
    Not sure what was going on but I took the above code and moved it from personal.xlsb into a separate workbook and voila it worked
    Option Explicit
    
    Private Declare Function URLDownloadToFile Lib "urlmon" _
    Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
    ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    Sub GetPageTitle()
        Dim i As Long, url As String
        For i = 1 To 4
            DoEvents
            url = "http://capnhud.host22.com/examples/" & Sheet1.Range("A" & i).Value & ".jpg"
            URLDownloadToFile 0, url, "C:\Documents and Settings\Owner\Desktop\media\download\" & Sheet1.Range("A" & i).Value & ".jpg", 0, 0
        Next
    End Sub
    Last edited by capnhud; 05-09-2012 at 09:42 AM.

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