Excel 2007 user defined type not defined

smiler44

Registered User.
Local time
Today, 09:57
Joined
Jul 15, 2008
Messages
671
below is my code. when I run this line
Dim FSO As Scripting.FileSystemObject

seems to error with message compile error user defined type not defined.

I have no idea how to define it, please can you advise?
thank you smiler44




Code:
Private Sub CommandButton1_Click()
    ' add headers
    With Range("A1")
        .Formula = "Folder contents:"
        .Font.Bold = True
        .Font.Size = 12
    End With
    Range("A3").Formula = "File Name:"
    Range("B3").Formula = "File Size:"
    Range("C3").Formula = "File Type:"
    Range("D3").Formula = "Date Created:"
    Range("E3").Formula = "Date Last Accessed:"
    Range("F3").Formula = "Date Last Modified:"
    Range("G3").Formula = "Attributes:"
    Range("H3").Formula = "Short File Name:"
    Range("A3:H3").Font.Bold = True
    ListFilesInFolder "C:\pictures", True
    
    MsgBox ("done")
    Exit Sub
End Sub
Sub ListFilesInFolder(SourceFolderName As String, IncludeSubfolders As Boolean)
' lists information about the files in SourceFolder
' example: ListFilesInFolder "C:\FolderName\", True
Dim FSO As Scripting.FileSystemObject
Dim SourceFolder As Scripting.Folder, SubFolder As Scripting.Folder
Dim FileItem As Scripting.File
Dim r As Long
    Set FSO = New Scripting.FileSystemObject
    Set SourceFolder = FSO.GetFolder(SourceFolderName)
    r = Range("A65536").End(xlUp).Row + 1
    For Each FileItem In SourceFolder.Files
        ' display file properties
        'Cells(r, 1).Formula = FileItem.Path & FileItem.Name
        Cells(r, 1).Formula = FileItem.Name
        Cells(r, 2).Formula = FileItem.Size
        Cells(r, 3).Formula = FileItem.Type
        Cells(r, 4).Formula = FileItem.DateCreated
        Cells(r, 5).Formula = FileItem.DateLastAccessed
        Cells(r, 6).Formula = FileItem.DateLastModified
        Cells(r, 7).Formula = FileItem.Attributes
        Cells(r, 8).Formula = FileItem.ShortPath & FileItem.ShortName
        
        r = r + 1 ' next row number
    Next FileItem
    'If IncludeSubfolders Then
    '    For Each SubFolder In SourceFolder.SubFolders
    '        ListFilesInFolder SubFolder.Path, True
    '    Next SubFolder
    'End If
    Columns("A:H").AutoFit
    Set FileItem = Nothing
    Set SourceFolder = Nothing
    Set FSO = Nothing
    ActiveWorkbook.Saved = True
    Exit Sub
End Sub
 
got it, go tools, references and check Microsoft scripting run time.

smiler44
 

Users who are viewing this thread

Back
Top Bottom