+ Reply to Thread
Results 1 to 10 of 10

Import from Web - Code Interruption

  1. #1
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Import from Web - Code Interruption

    Hello - I have a VBA code that extracts data from a website. At certain times, the code stops and the following message on the lower left corner of Excel appears "Contacting Server for Information". Now if I press the Esc button, the code resumes and runs fine.

    The problem is that the code takes a very long time to execute and will have to leave overnight to run. I basically need a line of code that automatically presses the Esc in case of a freeze.

    I appreciate all your help.

    Thank You,

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Import from Web - Code Interruption

    Can you post a sample of your code?

    Thanks

  3. #3
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Import from Web - Code Interruption

    Hi - Thank you for your prompt response. Below is a part of the code. I just omitted the name of the website.
    Please Login or Register  to view this content.

    The code basically loops from page 100 to 2000 and downloads the data onto Excel. This is only a part of the code so few things may not make sense to you. It's working perfectly except with the "Contact server for Information" message that I get sometimes with which I need to press the Esc button to overcome.

    Thanks
    Last edited by Leith Ross; 12-25-2013 at 02:22 PM. Reason: Added Code Tags

  4. #4
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Import from Web - Code Interruption

    Any suggestion?

    Thanks

  5. #5
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Import from Web - Code Interruption

    is this a problem you can repeat, in other words is it random ? I have been looking online for a solution but I have found none. I cannot replicate the issue because I don't have the whole code or the source. You could set a break point and see where the issue is and then try to determine its cause or how to fix it.

    what are you doing after importing the query? Are you copying it to a different location? You can delete all previous queries maybe it will fix it.

    I am sorry I cannot help more. Maybe if you share a little bit more of your code I might be able to take a look.

    Thanks

  6. #6
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Import from Web - Code Interruption

    Check this article I think will help with the problem

    http://social.technet.microsoft.com/...deployprevious

  7. #7
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Import from Web - Code Interruption

    Hi - What it I believe is causing this freeze is the internet connection. This is a very random freeze problem that may or may not occur. What's happening after the import has nothing to do with it. The freeze occur ONLY when trying to import. As I mentioned when this message appears in the lower left corner, hitting the escape button simply solves it. I tried to delete all previous queries, but this didnt' solve it.

    I was thinking maybe I can add the following line Application.SendKeys "{esc}", True that executes every 5 minutes while the main import code is also running. I chose 5 minutes because the import does not that more than 3 minutes. When this limit is exceeded I know that the code is frozen.

    I don't know if I mentioned, the freeze usually resolves by itself and the code resumes. Now this take 10 minutes or sometimes 40 minutes. I just need to bypass this to save on running time.

    Thanks

  8. #8
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: Import from Web - Code Interruption

    Yes, Send keys can be a solution. Now I am not sure if this will also cause the updating of the current query to be cancelled as well.
    But did you check my question in post #5? Are you saving the values of the query and then deleting the query before a new query is added?

    Is there a way you can share more of the code? I really would like to see what else is going on. Maybe there is something else that can be done to optimize it.

    Thanks

  9. #9
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Import from Web - Code Interruption

    Hi - Thank you for your support. I really wish not to share the code as I believe the code itself has no cause to the error.

    The imported data is dumped in excel and the previous query is deleted with the following code:

    'With ActiveSheet
    ' For i = .QueryTables.Count To 1 Step -1
    ' .QueryTables(i).Delete
    ' Next
    'End With

    and then it loops to the next page of the website..

    Is it possible to run two codes concurrently? I need while the main code is running, another code runs Application.SendKeys "{esc}", True every five minutes.

    I understand if you are no longer able to help.

    Thanks

  10. #10
    Registered User
    Join Date
    03-26-2008
    Posts
    44

    Re: Import from Web - Code Interruption

    Ok - Hi again. I believe I solved, well It's a work around. I placed the following:

    On Error GoTo Errhandler:
    '''Code goes here

    Errhandler:
    ' MsgBox Err & ": " & Error(Err)
    ' Application.Wait Now + TimeValue("00:00:5")
    Application.SendKeys "{esc}", True
    Resume

    Now the above automatically presses the Esc button when needed, however I am facing another problem now. Sometimes the code is interrupted and I will need to press the Continue button. Can I do this automatically WITHOUT disabling the Esc button(this will be needed to correct the original problem). I other words automatically press continue.

    Thanks

+ 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. Constant code interruption...
    By RayJay01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-22-2013, 07:00 PM
  2. UserForm or MsgBox without code interruption?
    By Riggers in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-20-2011, 07:45 AM
  3. Code Interruption
    By slim1313 in forum Excel General
    Replies: 3
    Last Post: 11-25-2009, 11:39 AM
  4. Visual Basic Code Interruption Message
    By richardlburkett in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-17-2008, 09:23 AM
  5. [SOLVED] Analysis ToolPak - VBA not allowing interruption of interations
    By Jeanne in forum Excel General
    Replies: 0
    Last Post: 01-20-2005, 01:06 PM

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