ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Processing a set of Excel Files (https://www.excelbanter.com/excel-programming/300454-processing-set-excel-files.html)

james

Processing a set of Excel Files
 
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.



TroyW[_2_]

Processing a set of Excel Files
 
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


"James" wrote in message
...
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.






All times are GMT +1. The time now is 05:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com