refresh external data using

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

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

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:

Convert Text to Columns in Excel 2010

If you have a cell in your Excel spreadsheet that contains a lot of text and you want to divide it into separate columns, this can only be done if there is a logical character which separates the text, for example, a comma.

Select the cells you would like to convert. On the Data tab, click Text to Columns. Choose the format of your current data.

Select Delimited if the text contains a logical character otherwise select Fixed Width if there are a certain number of spaces between each field.

Click Next when a preview of the data appears. Then select the type of character that separates the various fields. If the character is not listed, select Other and enter the character.

Click Next again and then choose the format for each of the columns. Select the column heading in the Data preview and then select a data type from the Column data format options.

Click Finish and the text will appear in several columns.

View all Excel hints and tips


Server loaded in 0.07 secs.