Consulting

Results 1 to 3 of 3

Thread: fixing error code get folder names and files names

  1. #1

    fixing error code get folder names and files names

    hi, expert i have folder calls cus and contains many sub folders cc1,cc2,cc3 each folder contains files types pdf or xls it supposes copying folder's name in col a and file's name in col b so i search in the internet to do that i got this code but not works it gives me error about function nod defined
    Private Sub ProcessFolder(fso As FileSystemObject, xFolder As Folder)
    HTML Code:
    Sub Get_MAIN_File_Names()   
     Dim fso As FileSystemObject    
    Dim xDirect As String    
    Dim xRootFolder As Folder   
     Dim DrawingNumb As String    
    Dim RevNumb As String   
     Dim rootFolderStr As String
        Set fso = New FileSystemObject   
     xRow = 0    
    
    With Application.FileDialog(msoFileDialogFolderPicker)      
     .Title = "Select Main File"       
    .Show
           'PROCESS ROOT FOLDER      
     If .SelectedItems.Count <> 0 Then         
     xDirect = .SelectedItems(1) & "\"         
     Set xRootFolder = fso.GetFolder(xDirect)         
     ProcessFolder fso, xRootFolder       End If
        End With
    End Sub
    Private Sub ProcessFolder(fso As FileSystemObject, xFolder As Folder)   
     Dim xFiles As Files    
    Dim xFile As File    
    Dim xSubFolders As Folders  
      Dim xSubFolder As Folder    
    Dim xSubFolderName As String   
     Dim xFileName As String    
    Dim xFileTime As String
        Set xFiles = xFolder.Files    'Adding Column names    
    Cells(1, "A").Value = "SubFolder Name"    
    Cells(1, "B").Value = "File Name"    
    Cells(1, "C").Value = "Modified Date/Time"
        For Each xSubFolder In xSubFolders  
     xSubFolderName = xSubFolder.Name   
    ActiveCell.Offset(xRow, 0) = xSubFolderName   
    xRow = xRow + 1
    Next xSubFolder
        'LOOPS THROUGH EACH FILE NAME IN FOLDER  
      For Each xFile In xFiles
          'EXTRACT INFORMATION FROM FILE NAME     
      xFileName = xFile.Name      
     xFileTime = xFile.DateLastModified
          'INSERT INFO INTO EXCEL       
    .Offset(xRow, 1) = xFileName       
    ActiveCell.Offset(xRow, 2) = xFileTime     
      xRow = xRow + 1   
    
     Next xFile
        Set xSubFolders = xFolder.SubFolders    
    
    For Each xSubFolder In xSubFolders       
     ProcessFolder fso, xSubFolder   
     Next xSubFolder
    End Sub

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Which line (of 50) don't you understand ?

  3. #3
    Quote Originally Posted by snb View Post
    Which line (of 50) don't you understand ?
    hi, snb actually i would fix the error then i see how is the code works and i will tell you what exactly i want but the problem in function tell me not defined

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •