Code to open multiple files from within a folder

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
.



Relevant Pages

  • RE: Code to open multiple files from within a folder
    ... I'm having problems with this script below. ... will open multiple files from within a folder. ... If .Execute()> 0 Then ...
    (microsoft.public.excel.programming)
  • Re: Startup Script from AD policy
    ... > the script so I can access it. ... > executable on the NETLOGON folder. ... > putting the executable under a shared folder with read/write permissions ... > How can I force the workstations to execute this remote file? ...
    (microsoft.public.windows.server.scripting)
  • Script to run rules
    ... I am wondering if it is possible to have a script select all of the read ... messages in a folder and then execute a rule? ... I want to schedule this to happen daily, to back up files on the server that ...
    (microsoft.public.mac.office.entourage)
  • Restricting execution of the tcl script to a folder or below
    ... receive a tcl script over the network in a folder allocated to a ... execute the script from this folder ...
    (comp.lang.tcl)
  • [kde] Re: plasma-desktop (KDE factory) acting up?
    ... example is another logging plasmoid that shows the output of a little ... script that outputs the state of my four drives every ten seconds. ... I have the group set to wheel for the logs I want to be read by trusted ... folder with pictures of people, and a subfolder with pictures of myself. ...
    (KDE)