Refresh Query on open failing

S

ssGuru

I'm getting a 1004 error when I try to refresh a query as I open a
Workbook using code.

The field named "LicActiveQuery" IS at at the top right of the table
that the query refreshes. Shouldn't I be able to use a named range
rather than a row col number as long as it is within the query result
table?

On Error Resume Next
Set wkbk = Workbooks("B.xls")
On Error GoTo 0
If wkbk Is Nothing Then
Set wkbk = Workbooks.Open(Filename:="C:\Data\ClientName
\B.xls")


'RANGE ERROR Creates an "Run-time error '1004':
' "Method 'Range' of object'_Worksheet' failed
Range("LicActiveQuery").QueryTable.Refresh
BackgroundQuery:=False


End If

Thanks,
Dennis
 
W

ward376

Try referring to the query table rather than a range:

yoursheet.QueryTables(1).Refresh BackgroundQuery:=False

Cliff Edwards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top