Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

320
Views
How to add multiple file paths in excel vba?

This code transfers filenames from one folder. How do add multiple file paths so it can transfer file names from multiple folders.

Sub get_files()
    Dim FsysObj As Object
    Dim objFolder As Object
    Dim objFiles As Object
   
    Dim SplitArray() As String
    Dim ID() As String
    Dim rowNo As Integer
    Dim fileName As String
    filepath = "D:/user"
    Set FsysObj = CreateObject("Scripting.FileSystemObject")
    Set objFolder = FsysObj.GetFolder(filepath)
    
    'clear the sheets
    Sheet1.Rows("1:" & Rows.Count).Delete
    
    Sheet1.Cells(1, 1).Value = "Lastname"
    Sheet1.Cells(1, 2).Value = "Firstname"
    Sheet1.Cells(1, 3).Value = "ID"
    rowNo = 2
        
    For Each file In objFolder.Files
             FirstName = Null
             LastName = Null
             ids = Null
             
        'get Base name of a file  without extension
        fileName = CreateObject("Scripting.FileSystemObject").GetBaseName(file.Name)
        
        SplitArray = Split(fileName, ", ")
        LastName = SplitArray(0)
        'Split with space to getting id and first name
        If UBound(SplitArray) = 1 Then
             ID = Split(SplitArray(1), " ")
        Else
            LastName = Null
        End If
          If (UBound(ID) = 1) Then
                FirstName = ID(0)
                ids = ID(1)
         End If
           
         'All values are found then stored it into excel sheet
       If Not (IsNull(FirstName) Or IsNull(LastName) Or IsNull(ids)) Then
            Sheet1.Cells(rowNo, 1).Value = LastName
            Sheet1.Cells(rowNo, 2).Value = FirstName
            Sheet1.Cells(rowNo, 3).Value = ids
            rowNo = rowNo + 1
        End If
      Next file

End Sub
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!