Results 1 to 4 of 4

Run-time Error 91 When Downloading File From Link

Threaded View

  1. #1
    Registered User
    Join Date
    01-03-2020
    Location
    U.S.A.
    MS-Off Ver
    365
    Posts
    11

    Run-time Error 91 When Downloading File From Link

    So I keep getting this 'Run-time error 91' 'Object variable with block variable not set'. I know there is a lot to read so thanks in advance for your time. The line is notated towards the bottom:

    Option Explicit
    
    Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
        ByVal pCaller As LongPtr, _
        ByVal szURL As String, _
        ByVal szFileName As String, _
        ByVal dwReserved As LongPtr, _
        ByVal lpfnCB As LongPtr) As LongPtr
    
    Sub DownloadSingleFile()
    
        Dim FileURl As String
        Dim DestinationFile As String
        Dim Ticker As String
    
        Ticker = Sheets("Grading Sheet").Cells(2, 2)
    
        FileURl = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        FileURl = "C:\VBA\VBA Download.zip"
        
        If URLDownloadToFile(0, FileURl, DestinationFile, 0, 0) = 0 Then
            Debug.Print "File download started"
        Else
            Debug.Print "File download not started"
        End If
        
        
    End Sub
    
    Sub LoadWebPage()
    
        Dim XMLReq As New MSXML2.XMLHTTP60
        Dim VidPageURL As String
        Dim Ticker As String
        
        Ticker = Sheets("Grading Sheet").Cells(2, 2)
        
        VidPageURL = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        
        XMLReq.Open "GET", VidPageURL, False
        XMLReq.send
        
        If XMLReq.Status <> 200 Then
            MsgBox "Problem" & vbNewLine & vbNewLine & XMLReq.Status & " - " & XMLReq.statusText
            Exit Sub
        End If
        
        FindFileLink XMLReq.responseText
        
    End Sub
    
    Sub FindFileLink(HTMLText As String)
        
        Dim HTMLDoc As New MSHTML.HTMLDocument
        Dim Links As MSHTML.IHTMLElementCollection
        Dim Link As MSHTML.IHTMLElement
        Dim VideoDiv As MSHTML.IHTMLElement
        
        Dim FileURl As String
        Dim Ticker As String
        
        Ticker = Sheets("Grading Sheet").Cells(2, 2)
        
        HTMLDoc.body.innerHTML = HTMLText
        
        Set VideoDiv = HTMLDoc.getElementsByClassName("t11b")(1)
        
        Set Links = VideoDiv.getElementsByTagName("a")
    
        Debug.Print Links.Length
        For Each Link In Links
            If Link.getAttribute("href") = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" Then
                Debug.Print Link.innerText, Link.getAttribute("href")
                Exit For
            End If
        Next Link
        
        FileURl = Link.getAttribute("href")                               'THIS IS THE LINE THAT IS HIGHLIGHTED WHEN THE ERROR BOX COMES UP
        FileURl = Mid(FileURl, InStr(FileURl, "http"))
        'Debug.Print FileURl
        
        DownloadFileFromPage FileURl
            
    End Sub
    
    Sub DownloadFileFromPage(FileURl As String)
    
        Dim DestinationFile As String
    
        FileURl = "C:\VBA\VBA Download.zip"
        
        If URLDownloadToFile(0, FileURl, DestinationFile, 0, 0) = 0 Then
            Debug.Print "File download started"
        Else
            Debug.Print "File download not started"
        End If
        
        
    End Sub
    Last edited by JBaum2000; 01-13-2020 at 06:20 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Error message: Run-Time error '1004 '; application-defined or object-defined error
    By Davasu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2015, 06:52 AM
  2. Replies: 1
    Last Post: 10-22-2015, 05:50 AM
  3. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  4. Cannot Publish Excel Pivot Chart - Run Time Error
    By crisb184 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2013, 07:04 AM
  5. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  6. run-time error ;2147023179 (800706b5) time automation error interface unknown
    By karthik72 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-02-2012, 09:31 AM
  7. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM

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