Dosya Araması Yapma isimli içerikte, ilgili işlemin VBA kodları ile nasıl yapacağınızı öğreten bir Hazır Makro Kodu yer almaktadır.
[*]Microsoft Visual Basic for Applications penceresini (Alt + F11) açın.
Yazdığınız yolda, istenen uzantıdaki dosyalar listelenecektir.
Faydalanılması temennisiyle.
[*]Microsoft Visual Basic for Applications penceresini (Alt + F11) açın.
Hazır Kod
VBA:
Private Sub btnara_Click()
comsonuc.Clear
Dim fso As Object, folder As Object, subfolder As Object, file As Object
Dim folderPath As String
Set fso = CreateObject("Scripting.FileSystemObject")
\' C:\ sürücüsünde mp3 dosyaları ara
folderPath = "C:\"
If fso.FolderExists(folderPath) Then
Set folder = fso.GetFolder(folderPath)
For Each file In folder.Files
If LCase(fso.GetExtensionName(file.Name)) = "mp3" Then
comsonuc.AddItem file.Path
End If
Next file
End If
\' C:\ sürücüsünde xlsb dosyaları ara
folderPath = "C:\"
If fso.FolderExists(folderPath) Then
Set folder = fso.GetFolder(folderPath)
For Each file In folder.Files
If LCase(fso.GetExtensionName(file.Name)) = "xlsm" Then
comsonuc.AddItem file.Path
End If
Next file
End If
Set fso = Nothing
End Sub
Açıklama
Diskteki istediğiniz dosyaları (alt klasörler dahil) nasıl bulacağınız ve bir ListBox'ta nasıl listeleyeceğiniz yazıyor. Bir UserForm üzerine, btnara ismli bir CommandButton ve ve comsonuc isimli bir ListBox yerleştirmeniz yeterli olacaktır.Yazdığınız yolda, istenen uzantıdaki dosyalar listelenecektir.
Faydalanılması temennisiyle.
Ekli dosyalar