Results 1 to 7 of 7

Thread: Runtime Error 7 Inconsistent

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    14

    Runtime Error 7 Inconsistent

    I'm a new to VB Forums and new to VB code as well so excuse me if there is something obvious I am missing. I am running code that produces a Runtime Error 7 message on the following code
    Code:
    Sheets("DIYGO").Select
    
    Range("D2:D45").Name = "RefreshRange"
    
    Range("RefreshRange").QueryTable.Refresh
    And errors out on the refresh. It works on other sheets just not this one and sometimes this one works and others do not. The code works fine by itself but when run with others, it gives me the error. The debugger claims it is the "Range("RefreshRange").QueryTable.Refresh" That has the problem. Once again, sometimes it works sometimes it doesn't. The range refreshed is web data. Thanks for your help.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Runtime Error 7 Inconsistent

    Welcome to VBForums

    Thread moved from the 'Application Deployment' forum (which is for questions about installing/distributing your software) to the 'Office Development/VBA' forum

  3. #3
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Runtime Error 7 Inconsistent

    If you want to refresh the query do not use the range and the table, refresh the connection itself. Something likeL

    ActiveWorkbook.Connections("MyQuery").Refresh

    Where MyQuery is the name of the query, do not mistake it for the name of the range.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    14

    Re: Runtime Error 7 Inconsistent

    Thank you for your quick response. I have about 200 separate web queries, would each one need to be refreshed individually as they are all from separate locations on the web or can I refresh an area or range of them? They are separated onto multiple sheets.

  5. #5
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Runtime Error 7 Inconsistent

    you can do something like

    vb Code:
    1. Dim myConn As Object
    2.  
    3. For Each myConn In ActiveWorkbook.Connections
    4.    myConn.Refresh
    5. Next myConn
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2011
    Posts
    14

    Re: Runtime Error 7 Inconsistent

    I still get the same error when I use that, although fortunately, it seems to be working now. I went basic and wrote
    Code:
    Dim x As Integer
    x = 4
    Dim y As Integer
    y = 3
    
    Sheets("sheet1").Select
    Cells(y, x).Select
    
    Range(ActiveCell, ActiveCell.Offset(43, 0)).Select
    Range("D3:D46").QueryTable.Refresh
    And for some reason, that is producing no new errors. It seems inconsistent and much more code then necessary but it works. Thanks for your help and if you have any idea why I might be getting these inconsistent errors, please let me know.

  7. #7
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: Runtime Error 7 Inconsistent

    I have no idea. But even in your code. All your lines do not affect the outcome exept for the last one. You can leave that alone and it will refresh the querytable in that particular range.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width