Results 1 to 14 of 14

Excel macro for retrieving file names

Threaded View

  1. #1
    Registered User
    Join Date
    01-10-2008
    Posts
    27

    Excel macro for retrieving file names

    Here is what i have:

    Sub findfiles()
    Application.ScreenUpdating = False
    Dim FN As String ' For File Name
    Dim ThisRow As Long
    Dim MyFileLocation As String
    MyFileLocation = "C:\temp\New Folder"
    FN = Dir(MyFileLocation)
    Do Until FN = "B10520-15-A-SL-F1-9901-.dwg"
    ThisRow = ThisRow + 1
    Cells(ThisRow, 1) = FN
    Cells(ThisRow, 2) = MyFileLocation + FN
    FN = Dir("C:\Temp\New Folder")
    Loop
    Application.ScreenUpdating = True
    End Sub
    When i do that, it sorta gets the job done. except all it says in the cells is: "C:\Temp\New Folder", and i want it to say the file name. not the path. i tried it again and got the results to read A file...but it was the same file all the way down to 7000 cells.

    Also, although this isnt a big deal, but it might affect your answer, it copies all the way down to the 66000th cell or what ever.

    Finally, after it does its thing and puts all that stuff in the cells, i get a small error in the line "Cells(ThisRow, 1) = FN" that says "run time error 1004 app defined or obj defined error"

    I heard that this is wrong because i have the directory too many times or something.

    Also, What do i put in where it says "Do Until FN = "B10520-15-A-SL-F1-9901-.dwg""


    Any guidance would be much appreciated.

    Thanks.

    paul
    Last edited by Leith Ross; 01-10-2008 at 07:02 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1