+ Reply to Thread
Results 1 to 9 of 9

Query's keep updating when they dont need too!

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Query's keep updating when they dont need too!

    Hi Guys,

    I have the following code, After running the macro, the query's want to keep updating. I want the query's to get the data once, and then stop updating afterwards (become static text). Does anyone have a method of making the query's static text?
    I think the auto updating of querys is ok when there are only a few, however I have a list of about 500, and which results in going very slow and eventually an error message coming up asking if I would like the query's to stop running, when I accept half of the querys become an error strings.

    (Column B has a list of website addresses.)


    Set Rng01 = Cells(3, 1)
    Set Rng02 = Cells(100, 1)
    'Call Functions_Module.BlanksToSkip(Rng01, "Down", Rng02, 1)
    
    For i01 = 1 To Rng02.Row - Rng01.Row - 1
    'URL = "http://www.wiseowl.co.uk/courses/"
    'URL = "https://www.linkedin.com/salary/Project-Engineer-salaries-in-australia"
    'Set ws = Worksheets.Add
    'Set qt = ws.QueryTables.Add(Connection:="URL;" & URL, Destination:=Range("A1"))
    
    URL = Cells(2 + i01, 2)
    Set Rng01 = Cells(2 + i01, 4)
    Set qt = ActiveSheet.QueryTables.Add(Connection:="URL;" & URL, Destination:=Rng01)
    
    With qt
    '    .RefreshOnFileOpen = True
    '    .RefreshPeriod = 5 ' (5 = 5 minutes, 0 will not refresh automatically)
    '    .Name = "OWLCourses"
    '    .WebFormatting = xlWebFormattingRTF
        .WebSelectionType = xlEntirePage
    '    .WebTables = "3"
    '    .WebTables = "1,2"
        .Refresh
    End With
    Application.Wait (Now + TimeValue("0:00:5"))
    
    Next i01
    
    End Sub
    Thanks,

    JimmyWilliams

  2. #2
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Re: Query's keep updating when they dont need too!

    I have attached the workbook with vba of what I am trying to do.
    I it seems to go very very slowly, and becomes very laggy; anyone know how to speed this up?
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Re: Query's keep updating when they dont need too!

    *Bumping Thread to get responses*
    Last edited by JimmyWilliams; 03-04-2020 at 10:25 AM.

  4. #4
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Re: Query's keep updating when they dont need too!

    *Bumping Thread to get responses*

  5. #5
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Re: Query's keep updating when they dont need too!

    *Bumping*
    I really don't know what I can do to improve my code. I need a way to change the query's into static text (I believe that it's probably the query refreshing each time the macro is looped through that is causing it to slow down around 50 querys.

  6. #6
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Query's keep updating when they dont need too!

    I have not much experience in this matter, but can you use this option?
    .BackgroundQuery = False
    B/R
    Erwin
    I started learning VBA because I was lazy ...
    Still developing.... being more lazy...

  7. #7
    Valued Forum Contributor Eastw00d's Avatar
    Join Date
    02-29-2020
    Location
    Breda, NL
    MS-Off Ver
    2016, 2019
    Posts
    833

    Re: Query's keep updating when they dont need too!

    For me this worked, but I have to admit, I deleted the rows below 150, because it takes about 45 seconds to complete to row 150, just for getting the data from internet, for only 10 rows.....
    With the first macro I turned background updating of the other cells off, I did this before executing the main procedure.
    Of course you have to update once in a while.....
    Sub Stop_Updating()
    Dim i
       For i = 3 To 150
        If Cells(i, 4) <> "" Then
            Cells(i, 4).QueryTable.BackgroundQuery = False
        End If
       Next i
    End Sub
    
    Sub importwiseowlcourses()
    Dim ws As Worksheet
    Dim qt As QueryTable
    Dim URL As String
    Dim Rng01 As Range
    Dim Rng02 As Range
    Dim i01 As Long
    
    Set Rng01 = Cells(3, 1)
    Call Functions_Module.BlanksToSkip(Rng01, "Down", Rng02, 1)
    
    For i01 = 140 To Rng02.Row - Rng01.Row - 1
    'URL = "http://www.wiseowl.co.uk/courses/"
    'URL = "https://www.linkedin.com/salary/Project-Engineer-salaries-in-australia"
    'Set ws = Worksheets.Add
    'Set qt = ws.QueryTables.Add(Connection:="URL;" & URL, Destination:=Range("A1"))
    
    URL = Cells(2 + i01, 2)
    Set Rng01 = Cells(2 + i01, 4)
    Set qt = ActiveSheet.QueryTables.Add(Connection:="URL;" & URL, Destination:=Rng01)
    
    Application.ScreenUpdating = False
    With qt
    '    .RefreshOnFileOpen = True
    '    .RefreshPeriod = 5 ' (5 = 5 minutes, 0 will not refresh automatically)
    '    .Name = "OWLCourses"
    '    .WebFormatting = xlWebFormattingRTF
        .WebSelectionType = xlEntirePage
    '    .WebTables = "3"
    '    .WebTables = "1,2"
            .BackgroundQuery = False
            .Refresh
        End With
     '   Application.Wait (Now + TimeValue("0:00:05"))
     '   Cells(2 + i01, 4).Copy                                  'I deselected those rows)
     '   Cells(2 + i01, 4).PasteSpecial Paste:=xlPasteValues
    Next i01
    Application.ScreenUpdating = True
    
    MsgBox ("ready")
    End Sub
    B/R
    Erwin
    Last edited by Eastw00d; 03-07-2020 at 11:01 AM. Reason: additional information

  8. #8
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Re: Query's keep updating when they dont need too!

    Hi Eastw00d,

    I've ran the "Sub Stop_Updating()" followed by your version of "Sub importwiseowlcourses()", however I am still getting the same problem.

    The "Sub Stop_Updating()"
    Doesn't do anything. (it's not called/used by the "Sub importwiseowlcourses()" and running "Sub Stop_Updating()" before running "Sub importwiseowlcourses()" doesnt add any extra value either.
    Not being rude, just factual. Thanks for trying.

    When I use your editted "Sub importwiseowlcourses()"
    but I am still running into the same problem; that it takes forever to go through the list. I'm still looking for a way/method to speed this process up and believe that its due to querys being updated when they don't need to be.

  9. #9
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Re: Query's keep updating when they dont need too!

    I am able to get the code to work for about 50 querys and then it slows down, I need to exit sub and then start again.
    Does anyone have a method where I could make this code run for 100's or 1000's of querys?
    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. Power Query: Updating a query based on changing tables
    By cheesehead101 in forum Excel General
    Replies: 1
    Last Post: 12-16-2019, 06:54 PM
  2. Updating ODBC query with VBA
    By codemancode in forum Access Tables & Databases
    Replies: 1
    Last Post: 05-02-2018, 03:45 PM
  3. Microsoft Query Updating
    By Jacobg38 in forum Excel General
    Replies: 2
    Last Post: 01-09-2017, 02:10 PM
  4. Add something to an updating query table
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-02-2013, 03:42 AM
  5. Replies: 1
    Last Post: 12-14-2009, 05:20 PM
  6. Updating a Web Query on Protected Sheet?
    By 007eko in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-25-2007, 08:51 PM
  7. updating query.
    By funkymonkUK in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-18-2006, 06:09 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