Solved

Excel VBA query

Posted on 2013-01-25
3
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Shanan212 earned 500 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

726 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