Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Opening files through code

TIA:

Trying to write code to open all files (one at a time) within specified folder

something like:
for each file with in folder c:\my documents
open
do something
save
close
next

Thanks, Joel
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Opening files through code

Hello Everyone...should have searched first but found prior post with solution.

Joel

"Joel" wrote:

TIA:

Trying to write code to open all files (one at a time) within specified folder

something like:
for each file with in folder c:\my documents
open
do something
save
close
next

Thanks, Joel

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Opening files through code

Hi Joel

This shoud do the trick for you.

Sub OpenChange()

Dim w As Workbook

With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.SearchSubFolders = False
.Filename = ".xls"
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.Open (.FoundFiles(i))
'Do stuff here.
For Each w In Workbooks
If w.Name < ThisWorkbook.Name Then
w.Close savechanges:=True
End If
Next w

Next i
Else
MsgBox "There were no files found."
End If
End With

End Sub

Regards

Marcus

Joel wrote:
TIA:

Trying to write code to open all files (one at a time) within specified folder

something like:
for each file with in folder c:\my documents
open
do something
save
close
next

Thanks, Joel


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
show most recent files first when opening excel files Anne` Excel Discussion (Misc queries) 5 January 23rd 08 01:54 AM
Opening Quattro Pro for Windows files (*.WB1 Files) using Excel 20 PoundMutt Excel Discussion (Misc queries) 1 June 20th 07 03:50 AM
run code on opening workbook and apply code to certain sheets Jane Excel Programming 7 August 8th 05 09:15 AM
How can I view files chronologically when opening multiple files Stevilsize Excel Discussion (Misc queries) 3 July 26th 05 12:49 AM
Opening Files with the Same Name MB Excel Discussion (Misc queries) 2 February 24th 05 11:41 PM


All times are GMT +1. The time now is 07:13 AM.

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"