+ Reply to Thread
Results 1 to 2 of 2

Macro Causing Excel to Restart

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

    Post Macro Causing Excel to Restart

    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.
    Last edited by JBaum2000; 01-13-2020 at 04:39 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro Causing Excel to Restart

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro keeps causing excel to freeze
    By tweacle in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-06-2019, 09:45 AM
  2. Macro causing excel to crash regularly
    By DavidBarker in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-16-2016, 08:04 PM
  3. Macro causing excel 2010 to crash
    By bradleyandrewdavis in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-16-2015, 09:44 AM
  4. Macro causing excel to crash
    By bradleyandrewdavis in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 05-16-2015, 04:29 AM
  5. ClearContent Macro causing Excel crash.
    By Phily915 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-23-2014, 12:54 PM
  6. [SOLVED] Macro causing Excel to freeze
    By Sassyponypants in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-04-2013, 06:10 AM
  7. VBA Macro Causing Excel To Crash - Can it Be More Efficient?
    By LoggersAW in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-02-2013, 08:49 PM

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