Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel VBA query

Posted on 2013-01-25
3
Medium Priority
?
225 Views
Last Modified: 2013-01-25
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?
0
Comment
Question by:classnet
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Shanan212 earned 2000 total points
ID: 38819783
mySheet.QueryTables(1).CommandText = mysheet.range("D12")
mySheet.QueryTables(1).refresh BackgroundQuery:=True

Open in new window


Let me know!
0
 

Author Comment

by:classnet
ID: 38819827
This yields a:

Application-defined or object-defined error

on this row

wksCaC.QueryTables(0).CommandText = wksCaC.Range("D12")
0
 

Author Closing Comment

by:classnet
ID: 38820432
Typo... thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
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 …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

877 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