Full Version: Refresh Query Macro
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
EAnderson
I have a button on a worksheet which I wish to refresh all the queries in the workbook.

CODE
Sub RefreshAll_Click()
Dim qt As QueryTable
Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        For Each qt In ws.QueryTables
            [color="red"]  qt.Refresh [/color]
        Next qt
    Next ws
End Sub


The highlighted code returns this error:

QUOTE
Run-time error '1004':

Application-defined or object-defined error


I've hunted around for an answer but the error message and words like query are all too common. Any ideas why this would be happening?

Thanks,

Edward
norie
Edward

Not sure about the error but why not give RefreshAll a shot instead of looping?
EAnderson
Works a treat. This command wasn't obvious to me sorry as I'm a VBA newbie.

Thank You crazy.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.