Excel VBA query

I have a SQL query in cell D12, Sheet1 in Excel 2007.

I'd like to refresh that query via a button... I don't want the query in B4 to execute.

These don't work:

mySheet.Range("D12").QueryTable.Refresh
mySheet.Range("D12").QueryTable().Refresh
mySheet.Range("D12").QueryTable(0).Refresh

Any ideas?
Sheldon LivingstonConsultantAsked:
Who is Participating?
 
Shanan212Connect With a Mentor Commented:
mySheet.QueryTables(1).CommandText = mysheet.range("D12")
mySheet.QueryTables(1).refresh BackgroundQuery:=True

Open in new window


Let me know!
0
 
Sheldon LivingstonConsultantAuthor Commented:
This yields a:

Application-defined or object-defined error

on this row

wksCaC.QueryTables(0).CommandText = wksCaC.Range("D12")
0
 
Sheldon LivingstonConsultantAuthor Commented:
Typo... thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.