View Full Version : Open all Workbook_Open event in folder
inajica
09-15-2008, 01:30 PM
I have 100 files in a folder named Find. Each file has a Workbook_Open event procedure. I need a code that will open each file, and perform the event procedure, close the workbook and go to the next file. Thank you
Bob Phillips
09-15-2008, 01:58 PM
Dim oFSO
Sub LoopFolders()
Set oFSO = CreateObject("Scripting.FileSystemObject")
selectFiles "c:\MyTest"
Set oFSO = Nothing
End Sub
'---------------------------------------------------------------------------
Sub selectFiles(sPath)
'---------------------------------------------------------------------------
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr
Set Folder = oFSO.GetFolder(sPath)
For Each fldr In Folder.Subfolders
selectFiles fldr.Path
Next fldr
For Each file In Folder.Files
If file.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=file.Path
'do your stuff
Activeworkbook.Close
End If
Next file
End Sub
inajica
09-15-2008, 03:17 PM
Thanks for the quick reply. But when I tried to run the code, nothing seems to happen. Should a certain references be checked. I already have Microsoft scripting runtime checked. Any help would be appreciated.
Bob Phillips
09-15-2008, 03:34 PM
You probably need to change
If file.Type = "Microsoft Excel Worksheet" Then
to
If file.Type Like "Microsoft*Excel*Worksheet*" Then
shamsam1
09-16-2008, 12:19 AM
i think this is correct
msoFileTypeExcelWorkbooks
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.