Solved

Excel VBA query

Posted on 2013-01-25
3
178 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 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need an Excel cell value to freeze once entered 8 34
Excel 3 24
cannot get subtotal to work 8 18
Quickbooks - Merging data 3 8
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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 …

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now