Solved

Refresh Data Query error

Posted on 2011-02-18
4
302 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now