Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
User type not defined
You need to reference th project to
Microsoft Scripting Runtime Tools - References in the VBE HTH "Steph" wrote: 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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
"User-defined type not defined" message in Excel | Excel Discussion (Misc queries) | |||
Workspace faux user-defined type not defined | Excel Programming | |||
User-defined data type; Error: Only User-defined types... | Excel Programming | |||
User Defined type not defined | Excel Programming | |||
Word.Document - user defined type not defined | Excel Programming |