Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

refresh external data using

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Refresh External Data using VBA

Refresh External Data using VBA

ResolvedVersion 2003

Amelie has attended:
Excel VBA Advanced course
PowerPoint Intermediate Advanced course

Refresh External Data using VBA

Hello,

I would like to write some code which would allow me to refresh all external data queries in all open workbooks. Could you please help?

Many thanks,

Amelie

RE: Refresh External Data using VBA

Hi Ameli

Thank you for your question

Could you refresh my recollection for me and advise which tool you are using to build your queries in the first place. Am I right in thinking that you are using the new database query tool in the data menu?

Thanks

Stephen

RE: Refresh External Data using VBA

Hi Stephen,

I indeed use the Database query tool.Data-Import External Data -Import Data and define some text files as my source files.


Thanks,

Amelie

RE: Refresh External Data using VBA

Hi Amelie

Thank you for your question

First let me apologise for the delay in response; I have been away from the office lately, and your question has taken a little bit of research.

The tool you refer to uses the querytables method of the worksheet object. It has three arguments, a connection string which locates the database, a destination which specifies where the data will go on the worksheet and an sql string to specify the table or query

The following is a simple example

Dim qtTable As QueryTable
sqlstring = "select FirstName from Employees"
cstring = ODBC;Database=Northwind"

With Sheets("Target").QueryTables.Add(Connection:=cstring, _
Destination:=Range("A1"), Sql:=sqlstring)
.Refresh
End With


Hope this is useful

Regards

Stephen

Tue 26 May 2009: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Create own ribbon tab - Excel 2010

a. In Excel click on the File tab
b. Select Options from left hand side
c. Choose the Customize Ribbon section
d. Click the New Tab button (below the list of tabs on the right hand side of the dialog box)
e. Select the New Tab (Custom) and enter a name, by clicking the Rename button (below the list of tabs on the right hand side of the dialog box)
f. Select the New Group (Custom) and enter a name, by clicking the Rename button (below the list of tabs on the right hand side of the dialog box)
g. Add commands to your tab and group by locating them on the list on the right hand side (remembering that you can change the list using the drop down box at the top of the list of commands) and clicking the Add button between the two panes to add them to your tab and group
h. You can rearrange the commands in your group, the groups on any tab or the tabs, using the up and down arrow buttons beside the list of tabs.
i. Click OK to apply your changes

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.