?
Solved

Refresh Data Query error

Posted on 2011-02-18
4
Medium Priority
?
314 Views
Last Modified: 2012-05-11
Hi,

I am trying to refresh an OLE DB query with some code.

I get the attached error whenever i run it my routine. The line of code it breaks on is

   Selection.QueryTable.Refresh BackgroundQuery:=False

I can phsyically refresh it on the spreadsheet, just not in the code.

Does anyone know why this is?

Thanks
Seamus
Doc1.doc
0
Comment
Question by:Seamus2626
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:SmittyPro
ID: 34928035
It's probably due to the Selection.  Try referencing the sheet object directly.

HTH,
0
 

Author Comment

by:Seamus2626
ID: 34928092
Heres my complete code, the sheet is called Raw Data, can you suggest?

Thanks
Seamus

    Sheets("Raw Data").Visible = True
    Sheets("Raw Data").Select
    Range("a22").Select
    Selection.QueryTable.Refresh BackgroundQuery:=False
    Range("a24").Select
    Sheets("Screen").Select
       
0
 
LVL 4

Accepted Solution

by:
SmittyPro earned 2000 total points
ID: 34928311
For Excel 2007+:

Sheets("Raw Data").Range("A22").ListObject.QueryTable.Refresh BackgroundQuery:=False

For 2003 -:

Sheets("Raw Data").Range("A22").QueryTable.Refresh BackgroundQuery:=False

And if all else fails:

ActiveWorkbook.RefreshAll

The sheet doesn't need to be visible/unhidden.


0
 

Author Closing Comment

by:Seamus2626
ID: 34928346
Good man!

ActiveWorkbook.RefreshAll

That worked

Cheers,
Seamus
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question