Processing a set of Excel Files

J

James

I have a set of Excel files I need to process. I have
code to determine the name and number of Excel files in a
directory.

What would the code be to cyle through the list of Excel
files, open each one & then close it when I've finished my
processing operation?

Thanks for your response.
 
T

TroyW

James,

Here is a basic code outline. I'm not sure how you have the list of file
names defined (array, defined name, cells on a worksheet, etc.).

Troy

Sub FileLoop()
Dim sFilename As String
Dim iNum As Integer
Dim ii As Integer

For ii = 1 To iNum
'Add logic here to assign sFilename to the next file.

Process_SingleFile sFile:=sFilename
Next ii
End Sub

Sub Process_SingleFile(sFile As String)
Dim wbFile As Workbook

'Open wbFile.
Set wbFile = Workbooks.Open(sFile)

'process wbFile here...

'Close wbFile and Save changes.
wbFile.Close SaveChanges:=True

Set wbFile = Nothing
End Sub
 
Top