Exporting file names to excel

  • Thread starter Thread starter tr2usa
  • Start date Start date
T

tr2usa

I would like to export file name from "Y:\ReleasedDrawings" to excel.
Can someone help me out?
Thanks
Vedat
 
A tried and true method, not dependent on the FSO:

To get it into code to run: press [Alt]+[F11] to open the VB Editor, use the
VB editors menu to Insert | Module and copy the code below and paste it into
the code module. Close the VB editor. Choose Tools | Macro | Macros from
the main Excel menu and run the ExportFileNames macro.

Sub ExportFilenames()
Const basicPath = "Y:\ReleasedDrawings\"
'change worksheet name and
'starting cell
'as needed for your workbook
Const wsName = "Sheet1"
Const startCell = "A2"

Dim anyFilename As String
Dim anyRange As Range
Dim rOffset As Long

rOffset = Cells(Rows.Count, Range(startCell).Column).End(xlUp).Row - 1
Set anyRange = Worksheets(wsName).Range(startCell)
Worksheets(wsName).Select
Application.ScreenUpdating = False ' improves speed
anyFilename = Dir$(basicPath & "*.*", vbNormal)
Do Until anyFilename = ""
anyRange.Offset(rOffset, 0) = anyFilename
rOffset = rOffset + 1
anyFilename = Dir$()
Loop
anyRange.Select
Application.ScreenUpdating = True

End Sub
 
A tried and true method, not dependent on the FSO:

To get it into code to run: press [Alt]+[F11] to open the VB Editor, use the
VB editors menu to Insert | Module and copy the code below and paste it into
the code module. Close the VB editor. Choose Tools | Macro | Macros from
the main Excel menu and run the ExportFileNames macro.

Sub ExportFilenames()
Const basicPath = "Y:\ReleasedDrawings\"
'change worksheet name and
'starting cell
'as needed for your workbook
Const wsName = "Sheet1"
Const startCell = "A2"

Dim anyFilename As String
Dim anyRange As Range
Dim rOffset As Long

rOffset = Cells(Rows.Count, Range(startCell).Column).End(xlUp).Row - 1
Set anyRange = Worksheets(wsName).Range(startCell)
Worksheets(wsName).Select
Application.ScreenUpdating = False ' improves speed
anyFilename = Dir$(basicPath & "*.*", vbNormal)
Do Until anyFilename = ""
anyRange.Offset(rOffset, 0) = anyFilename
rOffset = rOffset + 1
anyFilename = Dir$()
Loop
anyRange.Select
Application.ScreenUpdating = True

End Sub



I would like to export file name from "Y:\ReleasedDrawings" to excel.
Can someone help me out?
Thanks
Vedat- Hide quoted text -

- Show quoted text -

Thank you. This is perfect.
 

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

Back
Top