refresh external data using
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

Refresh External Data using VBA

resolvedResolved · Low Priority · Version 2003

replyReply Wed 29 Apr 2009, 16:24Delegate Amelie said...

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

For upcoming training course dates see: Pricing & availability

replyReply Thu 7 May 2009, 13:44Trainer Stephen said...

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

replyReply Thu 7 May 2009, 16:49Delegate Amelie said...

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

replyReply Mon 18 May 2009, 12:07Trainer Stephen said...

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.

 

Please browse our web site to find out more about
advanced excel seminar training and other Microsoft training courses.

Excel tip:

Toggle Formulas and Results

Ctrl + 'The key above Tab with the

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard