Hi lytsty,
Welcome to the forum!!
This should do the job:
Option Explicit
Sub Macro1()
'http://www.excelforum.com/excel-programming-vba-macros/858256-want-to-pull-file-names-from-folder-into-excel.html
'List all file names with extensions not found in 'vayMyArray' residing in the 'strMyDir' directory.
Dim strMyDir As String
Dim varMyArray As Variant
Dim objFSO As Object, _
objFile As Object
Dim lngMyRow As Long
strMyDir = "G:\" 'Directory to look in. Don't forget the trailing backslash.
varMyArray = Array("xml", "txt") 'Files with these extensions will be ignorged (i.e. not imported).
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Clear any existing imported file names from Col. A (starting at Row 2) from Sheet1. Change to suit.
lngMyRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
If lngMyRow >= 2 Then
Sheets("Sheet1").Range("A2:A" & lngMyRow).ClearContents
End If
lngMyRow = 0 'Initialise variable.
For Each objFile In objFSO.GetFolder(strMyDir).Files
If IsNumeric(Application.Match(objFSO.GetExtensionName(strMyDir & objFile.Name), varMyArray, 0)) = False Then
If lngMyRow = 0 Then 'Initial row number output. Change to suit.
lngMyRow = 2
Else
lngMyRow = lngMyRow + 1
End If
Sheets("Sheet1").Range("A" & lngMyRow).Value = objFile.Name
End If
Next objFile
Set objFSO = Nothing
Set objFile = Nothing
End Sub
Regards,
Robert
Bookmarks