• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

Klasördeki belgelerin isimlerini listelemek

Kod:
Sub DosyaListele()
     
    Dim objFSO As Object
    Dim objFolder As Object
    Dim objFile As Object
    Dim ws As Worksheet
     
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set ws = Worksheets.Add
     
     'Get the folder object associated with the directory
    Set objFolder = objFSO.GetFolder(ThisWorkbook.Path & "\Ocak 2017\")
    ws.Cells(1, 1).Value = objFolder.Name
     
     'Loop through the Files collection
    For Each objFile In objFolder.Files
        If Split(objFile, ".")(1) = "docx" Then
            ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = objFile.Name
        End If
    Next
     
     'Clean up!
    Set objFolder = Nothing
    Set objFile = Nothing
    Set objFSO = Nothing
     
End Sub
 
Alternatif;


Kod:
Sub listele()
  Range("A:A").ClearContents
  
  yol = ThisWorkbook.Path
  dosya = Dir(yol & "\Ocak 2017\*.doc?")
  
  sat = 0
  Do While dosya <> ""
    sat = sat + 1
    Cells(sat, "A").Value = dosya
    dosya = Dir
  Loop

  dosya = Dir(yol & "\Ocak 2017\*.pdf")
  Do While dosya <> ""
    sat = sat + 1
    Cells(sat, "A").Value = dosya
    dosya = Dir
  Loop

End Sub
 
Geri
Üst