top of page

Sub GetFirstFiveChars()
    Dim MyFolder As String
    Dim MyFile As String
    Dim i As Integer
    
    MyFolder = "C:\Folder\Path\" 'Change this to the path of your folder
    
    'Turn off screen updating and alerts to improve performance
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    'Clear any previous data in column A
    Range("A:A").ClearContents
    
    'Loop through all files in folder
    MyFile = Dir(MyFolder & "*.pdf")
    Do While MyFile <> ""
        'Get first five characters of filename
        Range("A" & i + 1).Value = Left(MyFile, 5)
        i = i + 1
        MyFile = Dir()
    Loop
    
    'Turn screen updating and alerts back on
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    
End Sub

bottom of page