View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Steph[_3_] Steph[_3_] is offline
external usenet poster
 
Posts: 312
Default User type not defined

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