View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default User type not defined

Hi Steph,

You need to set a reference to the "Microsoft Scripting Runtime" using
the Tools/References menu in the Visual Basic Editor. This is the type
library that contains the FileSystemObject used in the code below.

--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/

* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm

"Steph" wrote in message
...
Hello. I grabbed this bit of code a while ago off of the newsgroups, but
actually tried to use it today. When run, it gives me the Compile error:
User defined type not defined. Did I not copy a section of the code that
I
needed? Thanks!

Sub Open_all_files() 'Opens all files in folder AND Subfolders

Dim FSO As Scripting.FileSystemObject
Dim TopFolder As String
Set FSO = New Scripting.FileSystemObject
TopFolder = "G:\G&A Test" '<<<<<<<<< CHANGE THIS TO TOP FOLDER
InnerProc FSO.GetFolder(TopFolder), FSO

End Sub

Sub InnerProc(F As Scripting.Folder, FSO As Scripting.FileSystemObject)

Dim SubFolder As Scripting.Folder
Dim OneFile As Scripting.File
Dim WB As Workbook

For Each SubFolder In F.SubFolders
InnerProc SubFolder, FSO
Next SubFolder
For Each OneFile In F.Files
Debug.Print OneFile.Path
If Right(OneFile.Name, 4) = ".xls" Then
Set WB = Workbooks.Open(Filename:=OneFile.Path)

'****Code that does stuff here*****

WB.Close savechanges:=True
End If
Next OneFile

End Sub