|
|
|
|
|
|
Excel
|
Process All Workbooks in a Given Directory Folder
|
|
Ease of Use
|
Intermediate
|
Version tested with
|
2000
|
Submitted by:
|
Steiner
|
Description:
|
Run your code in a folder full of workbooks.
|
Discussion:
|
Sometimes you need code that opens all workbooks in a given directory, does something, and then closes them again. This is just an example to get you started, because it does nothing except print the name of the workbook.
|
Code:
|
instructions for use
|
Sub ProcessAll(sPath As String)
Dim Wb As Workbook, sFile As String
sFile = Dir(sPath & "*.xls")
Do While sFile <> ""
Set Wb = Workbooks.Open(sPath & sFile)
Debug.Print Wb.Name
Wb.Close False
sFile = Dir
Loop
End Sub
|
How to use:
|
- Copy the code above.
- Open your workbook and hit Alt+F11 to open the VB Editor (VBE).
- From the menu, choose Insert-Module.
- Paste the code into the code area of the module at right.
- Close the VBE.
|
Test the code:
|
- Place some Excel files together with other stuff in a directory.
- Make sure none of the Excel files is password protected (though this code can be altered to allow for it--just ask at our forum).
- Go to Tools-Macro-Macros and double-click on ProcessAll.
|
Sample File:
|
No Attachment
|
Approved by Anne Troy
|
This entry has been viewed 314 times.
|
|