+ Reply to Thread
Results 1 to 3 of 3

Directory Listing code - Mod?

Hybrid View

  1. #1
    Registered User
    Join Date
    08-01-2007
    Posts
    49

    Directory Listing code - Mod?

    Hello, how can i specify a directory in code and copy all its filing structure, so for every xls file within the folder i specify it will list it in a spreadsheet.

    Thanks for your time, RoyUK has a code on his own website for opening the xls files but i want it to list the path.

    HTML Code: 
    -RoyUK's Code

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Are you using Excel 2007? If you are change .xls to the relevant 2007 extension

    Option Explicit
    
    
    Sub Lis_All_Files()
        Dim sFil   As String
        Dim sPath  As String
        Dim r      As Long
    
        sPath = "C:\Documents and Settings\Roy Cox\My Documents\"    'location of files
        ChDir sPath
        sFil = Dir("*.xls")    'change or add formats
        r = 2
        Do While sFil <> ""    'will start LOOP until all files in folder sPath have been looped through Set oWbk = Workbooks.Open(sPath & "\" & sFil) 'opens the file
            With ActiveSheet
                .Cells(r, 1).Value = sFil
                r = r + 1
            End With
            sFil = Dir
        Loop    ' End of LOOP
    End Sub
    Last edited by royUK; 08-13-2007 at 03:33 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    You may also find this of interest

    http://www.vbaexpress.com/kb/getarti...da54213fdf7d82

    It lists all files & sub folders of a directory
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ Reply to Thread

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