Search

VBA to list all file names in any Folder or Directory


You can use the below VBA code to list specified files types from Directory. Below demo sample code will list all .mp3 files in folder/directory "D:\Music\5 Seconds Of Summer\"

If you want to list other files type for example .xlsm files change "*.mp3" to "*.xlsm", or to list all files irrespective 
change it "*.mp3" to "*.*".

Please share or comment below if you have any questions.

Const vDir As String = "D:\Music\5 Seconds Of Summer\"
Const vPttrn As String = "*.mp3"
Dim vFile As String

Sub test_list_mp3_files()

'-----------------------------
'Thanks for downloading the code. 
'Please visit our channel for a quick explainer on this code.
'Feel free to update the code as per your need and also share with your friends.
'Channel: Youtube.com/vbaa2z
'Download free codes from http://vbaa2z.blogspot.com
'Autor: L Pamai (vbaa2z.team@gmail.com)
'-----------------------------

vFile = Dir(vDir & vPttrn, vbNormal)

Do While Len(vFile) > 0
    Debug.Print vFile
    vFile = Dir
Loop

End Sub

for more please visit http://bit.ly/2dveQPZ

No comments:

Post a Comment

Note: only a member of this blog may post a comment.