Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Best way to refresh data from an external file

What I'm doing:
Replacing all the data in a worksheet with new data from
a .txt file.

The code I'm using (I'm refreshing two worksheets here):
Sub RefreshPensionWelfareData()
' Refresh Pension worksheet with the Pension .txt file.

Application.Goto Reference:="PensionData"
Selection.QueryTable.Refresh BackgroundQuery:=False

Application.CutCopyMode = False
Range("B1").Select

' Refresh the Welfare sheet with the Welfare.txt file.

Application.Goto Reference:="WelfareData"
Selection.QueryTable.Refresh BackgroundQuery:=False

Application.CutCopyMode = False
Range("B1").Select
End Sub

The question:
This is working but I am new to VBA and do not understand
how Excel knew which file is which or where it is without
showing the path to the file in any of the code above.
Is the code above an acceptable way of refreshing the
data? And is there a place in Excel where I can go to see
the SQL or where the path to the file is stored? I see
that if the path is changed I can go to Data, Get External
Data and Edit Text Import to navigate to the file.
Thanks,
Sharon
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Best way to refresh data from an external file

Maybe I can answer my own question.
Who knows if its the best way but it works.
and when I clicked Refresh Data I had to navigate to the
file I wanted to use. If you record a macro Excel does not
include the path to that file in the code. Perhaps that is
because you might move the file and then Excel could not
change your macro so it just keeps the info in some kind
of background query. Just guessing.
Thanks anyway -
Sharon
-----Original Message-----
What I'm doing:
Replacing all the data in a worksheet with new data from
a .txt file.

The code I'm using (I'm refreshing two worksheets here):
Sub RefreshPensionWelfareData()
' Refresh Pension worksheet with the Pension .txt file.

Application.Goto Reference:="PensionData"
Selection.QueryTable.Refresh BackgroundQuery:=False

Application.CutCopyMode = False
Range("B1").Select

' Refresh the Welfare sheet with the Welfare.txt file.

Application.Goto Reference:="WelfareData"
Selection.QueryTable.Refresh BackgroundQuery:=False

Application.CutCopyMode = False
Range("B1").Select
End Sub

The question:
This is working but I am new to VBA and do not understand
how Excel knew which file is which or where it is without
showing the path to the file in any of the code above.
Is the code above an acceptable way of refreshing the
data? And is there a place in Excel where I can go to see
the SQL or where the path to the file is stored? I see
that if the path is changed I can go to Data, Get

External
Data and Edit Text Import to navigate to the file.
Thanks,
Sharon
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Best way to refresh data from an external file

Sharon

When I record a macro it does record the path - I'm not sure why yours is
different. The file and path are stored in two places actually. The
Connection property of the QueryTable object stores the DSN connections
string which will contain the path and the CommandText property (SQL string)
also contains the path. If you go to the immediate window and type

?Sheet1.QueryTables(1).Connection
?Sheet1.QueryTables(1).CommandText

you can see what it is storing for that querytable. As these are strings,
you can also change them before you refresh.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Sharon" wrote in message
...
Maybe I can answer my own question.
Who knows if its the best way but it works.
and when I clicked Refresh Data I had to navigate to the
file I wanted to use. If you record a macro Excel does not
include the path to that file in the code. Perhaps that is
because you might move the file and then Excel could not
change your macro so it just keeps the info in some kind
of background query. Just guessing.
Thanks anyway -
Sharon
-----Original Message-----
What I'm doing:
Replacing all the data in a worksheet with new data from
a .txt file.

The code I'm using (I'm refreshing two worksheets here):
Sub RefreshPensionWelfareData()
' Refresh Pension worksheet with the Pension .txt file.

Application.Goto Reference:="PensionData"
Selection.QueryTable.Refresh BackgroundQuery:=False

Application.CutCopyMode = False
Range("B1").Select

' Refresh the Welfare sheet with the Welfare.txt file.

Application.Goto Reference:="WelfareData"
Selection.QueryTable.Refresh BackgroundQuery:=False

Application.CutCopyMode = False
Range("B1").Select
End Sub

The question:
This is working but I am new to VBA and do not understand
how Excel knew which file is which or where it is without
showing the path to the file in any of the code above.
Is the code above an acceptable way of refreshing the
data? And is there a place in Excel where I can go to see
the SQL or where the path to the file is stored? I see
that if the path is changed I can go to Data, Get

External
Data and Edit Text Import to navigate to the file.
Thanks,
Sharon
.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
External Data Refresh all just for one worksheet Andy Excel Discussion (Misc queries) 3 April 23rd 09 03:33 PM
External data refresh Texas Tonie[_2_] Excel Discussion (Misc queries) 1 April 17th 07 11:02 AM
Pivot Table external XLS file source change and GETPIVOTDATA refresh mbobro Excel Discussion (Misc queries) 0 July 8th 06 12:45 PM
external data refresh shoreguy Excel Discussion (Misc queries) 0 March 7th 06 06:30 PM
External Data Refresh not working Mike B in VT Excel Discussion (Misc queries) 0 February 10th 06 06:23 PM


All times are GMT +1. The time now is 02:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"