Results 1 to 1 of 1

VBA - Go to website and download file from save prompt

Threaded View

randiba VBA - Go to website and... 05-22-2013, 08:33 PM
  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    Florida, US
    MS-Off Ver
    Excel 2007
    Posts
    6

    VBA - Go to website and download file from save prompt

    Hello,

    I've been spending the last few hours trying to figure out how to save a file onto the computer using VBA. The code template below that I found on another forum seems promising, except when I go to the desktop to access it, the .csv file has what looks like the page's source code instead of the actual file I want. This may be because when I go to the url, it doesn't automatically download the file; rather, I am asked to save the file to a certain location (since I don't know the path name of the uploaded file on the site).
    Is there any way to alter this code to accomodate this, or will I have to use a different code entirely? Thanks!

    Sub Test()
        Dim FileNum As Long
        Dim FileData() As Byte
        Dim MyFile As String
        Dim WHTTP As Object
        
        On Error Resume Next
            Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
            If Err.Number <> 0 Then
                Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
            End If
        On Error GoTo 0
        
        
        MyFile = "MY_URL_HERE"
        
        WHTTP.Open "GET", MyFile, False
        WHTTP.send
        FileData = WHTTP.responseBody
        Set WHTTP = Nothing
        
        If Dir("C:\Users\BLAHBLAH\Desktop", vbDirectory) = Empty Then MkDir "C:\Users\BLAHBLAH\Desktop"
        
        FileNum = FreeFile
        Open "C:\Users\BLAHBLAH\Desktop\memberdatabase.csv" For Binary Access Write As #FileNum
            Put #FileNum, 1, FileData
        Close #FileNum
        
    End Sub
    Cross-posts:
    http://www.ozgrid.com/forum/showthread.php?t=178884
    http://stackoverflow.com/questions/1...om-save-prompt
    Last edited by randiba; 05-24-2013 at 08:03 PM. Reason: citing crossposts

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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