Solved

Refresh Data Query error

Posted on 2011-02-18
4
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

756 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