+ Reply to Thread
Results 1 to 3 of 3

VBA QueryTables

  1. #1
    Registered User
    Join Date
    02-11-2019
    Location
    Chicago, IL
    MS-Off Ver
    2016
    Posts
    8

    VBA QueryTables

    I have a macro that uses QueryTables. I am a novice with VBA and basically took this code from a webpage. My macro works fine most of the time, but sometimes excel will stop responding. When this happens, the debugger takes me to .Refresh BackgroundQuery:=False from the below code. If I shut down excel and start it back up again and run the exact same macro again, it usually works fine so I do not think it has anything to do with incorrect URLs passing through rhyperlink.

    Here is an excerpt of the code that is having the issue:

    Please Login or Register  to view this content.
    What I am ultimately asking is 1) any ideas what could be causing excel to stop responding and require me to shut it down on occasion? 2) can someone explain what each of the properties are doing in this code (other than .Add which is self-explanatory to me)?

    As a side note, this code is inside of a loop and rhyperlink is updated in each loop. For each unique rhyperlink, there is a named range that gets created (actually 2 because I copy the querytable to another tab in each loop). Is there a way to prevent each querytable resulting in a new named range - is it related to .SaveData = True?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: VBA QueryTables

    Hello mrdomer07,

    Your code is simply copying tables from a website to the ActiveSheet. If the website fails to respond and maintains an open connection, it will hang Excel. There are no properties you can set in the Query to "cancel" the operation if this situation arises.

    There are other ways to copy web tables. You should post the full code the Query is in. It is possible there may be some other code causing problems with the Query. The best option would be to attach a copy of the workbook for review. If your workbook contains sensitive, confidential, or personal information then redact or change it before you post.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    02-11-2019
    Location
    Chicago, IL
    MS-Off Ver
    2016
    Posts
    8

    Re: VBA QueryTables

    Hi Leith - Here is my spreadsheet. I deleted most of the tabs in the file to make it more manageable but I do not think it broke anything. I ran the Macro_Scrape macro on the InputMacro tab as a test and it worked with no problem. As a quick tutorial, B2 of the InputMacro tab dictates the first URL link that will be generated. B3 dictates the last URL that will be generated. So if you start with B2 = 4, then if you set B3 = 10 then it will run 7 loops and scrape 7 web pages.

    The macro is fairly cobbled together with code I found here and there but it works. Any suggestions you have to make the QueryTables section more stable/reliable or to generally improve the code would be very much appreciated. Thanks in advance!
    Attached Files Attached Files

+ 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. Querytables.add issue
    By nerdzkilla in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-23-2012, 10:26 AM
  2. two querytables two worksheets
    By Kiethlard in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-09-2010, 05:15 AM
  3. QueryTables.Add timeout?
    By shai1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-26-2010, 03:51 PM
  4. Web query with QueryTables
    By fredoman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-03-2009, 07:42 PM
  5. QueryTables command
    By Sharlene England in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2006, 08:10 PM
  6. listobjects and querytables
    By S. Parker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-14-2005, 05:10 AM
  7. ActiveSheet.QueryTables.Add
    By Rick in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-10-2005, 12:30 AM
  8. [SOLVED] QueryTables Add
    By Marta in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-19-2005, 02: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