Why would a macro cause Excel to restart?
My code has no 'restart excel' commands but when I run my macro the VB editor says "Not Responding" at the top for a second before the excel file restarts without the VB editor open. This did not happen until I added the following :
"DownloadFileFromPage FileURl"
The rest of the code is the following:
#
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
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")
FileURl = Mid(FileURl, InStr(FileURl, "http"))
'Debug.Print FileURl
DownloadFileFromPage FileURl 'this is the problematic line, if I take it out it won't restart, if I keep it in it restarts.
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
#
Why might this cause excel to restart? I can add more of the code if you believe it may help get a better picture.
Bookmarks