[AccessD] Excel to MDB

MartyConnelly martyconnelly at shaw.ca
Thu May 10 14:26:29 CDT 2007


You can do with Dir but I find the recursion easier with FSO

Sub test()
'List all files and directories under a folder recursively
Dim oFSO As Object
    Set oFSO = CreateObject("Scripting.FileSystemObject")
ListFiles oFSO, "C:\Access files\Directories"
Set oFSO = Nothing
End Sub

Function ListFiles(oFSO As Object, FolderName As String)
    Dim pFile As Object 'Scripting.File
    Dim pFolder As Object 'Scripting.Folder
        Dim oFolder As Object 'Scripting.Folder
  
    With oFSO.GetFolder(FolderName)
     Debug.Print "Folder ----  "; EndSlash(FolderName)
        For Each pFile In .Files
          Debug.Print " ----  "; pFile.Name; pFile.DateLastModified
        Next
 
        For Each pFolder In .subFolders
            ListFiles oFSO, pFolder.path
        Next
    End With
End Function

Function EndSlash(sPath)
 If Not Right(sPath, 1) = "\" Then sPath = sPath & "\"
 EndSlash = sPath
End Function


Arthur Fuller wrote:

>Imagine this, if you will:
>
>A potential client invented an Excel system for doing estimates and orders.
>Each estimate or order is a separate file. There are subdirs named for each
>client. There are now hundreds of Excel files.
>
>Now the potential client has realized the error of his ways and wants to
>import everything into an Access db and stop using Excel.
>
>I haven't seen the data yet, so I can only hope and pray that the Excel
>files all work from the same template. Otherwise all hell breaks lose.
>
>But supposing that in this best of all possible worlds, all the Excel files
>are structurally similar. I already know how to talk to a given Excel file
>and extract its contents into various tables. What I don't know is how to
>walk the directory tree and examine and extract from every file I find in
>said tree. I think it has something to do with the Dir() function, but I've
>forgotten.
>
>TIA,
>Arthur
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada




More information about the AccessD mailing list