Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Macro to refresh data from different files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cam - 18 Mar 2008 14:36 GMT
Hello,

I have a standard chart and data on several files, 1 file for each product.
The data for each file is imported from Access. I created a master file which
link the data from each product file. How do I create a macro to go to all
the product files, to refresh all the data which in turn will update the
master file? Thanks
Dick Kusleika - 18 Mar 2008 22:36 GMT
>I have a standard chart and data on several files, 1 file for each product.
>The data for each file is imported from Access. I created a master file which
>link the data from each product file. How do I create a macro to go to all
>the product files, to refresh all the data which in turn will update the
>master file? Thanks

Are they all in the same directory?  Do they all have similar names?  How
would you identify which files to open?
Signature

Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com

Cam - 19 Mar 2008 19:24 GMT
Hi Dick,

All files are in a same folder on the same network directory, but they all
have a different file name. So, instead of having to open all the files then
click a fresh all button on each file, I want a master macro to go in each
file and refresh the pivot tables, etc..

> >I have a standard chart and data on several files, 1 file for each product.
> >The data for each file is imported from Access. I created a master file which
[quoted text clipped - 4 lines]
> Are they all in the same directory?  Do they all have similar names?  How
> would you identify which files to open?
Dick Kusleika - 20 Mar 2008 00:02 GMT
>Hi Dick,
>
[quoted text clipped - 5 lines]
>> Are they all in the same directory?  Do they all have similar names?  How
>> would you identify which files to open?

Cam:  This isn't tested, so let me know if you run into troubles with it.
Change sFldr to point to the right place.

Sub RefreshAllFiles()
   
   Dim sFldr As String
   Dim ws As Worksheet
   Dim pt As PivotTable
   Dim sFile As String
   Dim wb As Workbook
   
   sFldr = "\\Server1\MyFolder\*.xls"
   
   sFile = Dir(sFldr) 'get the first xls file
   
   Do Until Len(sFile) = 0
       Set wb = Workbooks.Open(sFile)
       For Each ws In wb.Worksheets
           For Each pt In ws.PivotTables
               pt.RefreshTable
           Next pt
       Next ws
       wb.Save
       wb.Close False
       sFile = Dir 'get the next xls file
   Loop
   
End Sub
Signature

Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.