Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Code to open multiple files from within a folder
Thanks for your help guys.
Kind regards Karen "Karen" wrote: Hi all, I'm having problems with this script below. I need some Excel VBA code that will open multiple files from within a folder. Sometimes there maybe 5 files to open, sometimes there may be more. I will never know how many files will be in the folder each time I execute the code, and I won't know the file names in the folder either. The script below is nearly correct, however it seems to retain the file names from the last time it was executed. I need a way of flushing it out so it doesn't retain anything when it ends. If it retains the file names then it expects them to be there when it is next executed, which of corse causes errors. Thanks for any help with this - regards Karen. The script I'm using is pasted below. With Application.FileSearch .NewSearch .LookIn = "C:\testfolder" .SearchSubFolders = False .Filename = "*.xls" .MatchTextExactly = True .FileType = msoFileTypeExcelWorkbooks If .Execute() 0 Then MsgBox "There were " & .FoundFiles.Count & " file(s) found." For i = 1 To .FoundFiles.Count Workbooks.Open Filename:=.FoundFiles(i) MsgBox .FoundFiles(i) Next i End If End With |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Code to open multiple files from within a folder | Excel Programming | |||
User selection of folder and open all .xls files within folder | Excel Programming | |||
Open files in folder - skip if already open | Excel Programming | |||
Open all files in a folder | Excel Programming | |||
open all files in a folder and ... | Excel Programming |