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
Bookmarks