workbook file name

R

Ranjith Kurian

I have nearly 50 workbooks(.csv format) in a folder, i need a macro to copy
all the workbooks Names to a new worksheet.
 
M

MRT

Try...

Private Function GetPath()
Dim strPath As String
MsgBox "Select Folder"
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = True Then
strPath = .SelectedItems(1)
End If
End With
GetPath = strPath
End Function

Sub File_List()
Dim strPath As String
Dim strFName As String
Dim n As Long
strPath = GetPath
If strPath = "" Then Exit Sub
If Right(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
strFName = Dir(strPath & "*.csv")
Do While strFName <> ""
n = n + 1
Cells(n, 1).Value = strFName
strFName = Dir()
Loop
End Sub

HTH
 
J

Jacob Skaria

Hi Ranjith

Try the below macro which will list all the .csv (comma seperated values)
file names in the folder to Col A...Adjust the folder name to suit.

Sub FileswithinFolder()
Dim strFile As String, strFolder As String, intCount As Integer
strFolder = "c:\temp"
strFile = Dir(strFolder & "\*.csv", vbNormal)
Do While strFile <> ""
intCount = intCount + 1
Range("A" & intCount) = strFile
strFile = Dir
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top