Link to home
Start Free TrialLog in
Avatar of Seamus2626
Seamus2626Flag for Ireland

asked on

Refresh Data Query error

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
Avatar of SmittyPro
SmittyPro
Flag of United States of America image

It's probably due to the Selection.  Try referencing the sheet object directly.

HTH,
Avatar of Seamus2626

ASKER

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
       
ASKER CERTIFIED SOLUTION
Avatar of SmittyPro
SmittyPro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good man!

ActiveWorkbook.RefreshAll

That worked

Cheers,
Seamus