I am trying to printout all the *.pdf files in a directory "G:\Accounts". There are multiple subdirectories and each subdirectory may have multiple subdirectories. I've tried to copy code from VBA Developer's Handbook & from utteraccess without luck.
Here is the code from utteraccess
Sub try()
'required to launch SubFileFolderList(varFolder)
pstrPath = "G:\Accounts\"
Call FileFolderList(varFolder)
End Sub
Public Sub FileFolderList(varFolder)
'copied from utteraccess.com
'1020831&type=thread
'c. canter 6/21/07
'---------------------------------------------------------
Dim colFolders As New Collection
Dim strName As String
If Right(pstrPath, 1) <> "\" Then pstrPath = pstrPath & "\"
strName = Dir(pstrPath, vbDirectory)
Do While strName <> ""
If (GetAttr(pstrPath & strName) And vbDirectory) = vbDirectory Then
If strName <> "." And strName <> ".." Then colFolders.Add pstrPath
Debug.Print pstrPath & strName
Else
ActiveCell.Offset(0, 1).Value = strName
ActiveCell.Offset(1, 0).Select
End If
strName = Dir
Loop
For Each varFolder In colFolders
Call FileFolderList(varFolder)
Next varFolder
Set colFolders = Nothing
End Sub
This does not appear to be listing the files in the particular subdirectories of G:\Accounts\ I'm trying to search. In Truth, I'm not sure what it is listing.
I also tried
Sub ListSubDirs()
'--------------------------------------------------------------------
'copied from "VBA Developer's Handbook", Ken Getz & Mike Gilbert
'page 661
'c. canter 6/21/07
'--------------------------------------------------------------------
Dim strSubDir, strFile As String
Dim MyAttr As Integer
strPath = "G:\Accounts\"
'Make sure strPath is a directory
'find all the files, including directories
strSubDir = Dir(strPath, vbDirectory)
Do Until strSubDir = ""
If strSubDir <> "." And strSubDir <> ".." Then
ActiveCell.Value = strSubDir
'-------------------------------------------------------------------------
'this section prints all the files in the subdirectory
'from page 656
'-------------------------------------------------------------------------
strSubPath = strPath & strSubDir & "\"
strFile = Dir(strSubPath, vbDirectory)
Do Until strFile = ""
ActiveCell.Offset(1, 0).Select
MyAttr = GetAttr(strFile)
ActiveCell.Offset(0, 1).Value = strFile
strFile = Dir
Loop
'-------------------------------------------------------
ActiveCell.Offset(1, 0).Select
End If
strSubDir = Dir
Loop
End Sub
This routine does not dive into the lower subdirectories.
Any suggestions? Which routine is better? I have to determine if 900 items are in this G:\Accounts\. The plan is to list all the drawings in .pdf file and do a vlookup against the two lists.
Please help. I am really behind the eight ball on this one
Craig Canter
Controller
Elgin IL
Here is the code from utteraccess
Sub try()
'required to launch SubFileFolderList(varFolder)
pstrPath = "G:\Accounts\"
Call FileFolderList(varFolder)
End Sub
Public Sub FileFolderList(varFolder)
'copied from utteraccess.com
'1020831&type=thread
'c. canter 6/21/07
'---------------------------------------------------------
Dim colFolders As New Collection
Dim strName As String
If Right(pstrPath, 1) <> "\" Then pstrPath = pstrPath & "\"
strName = Dir(pstrPath, vbDirectory)
Do While strName <> ""
If (GetAttr(pstrPath & strName) And vbDirectory) = vbDirectory Then
If strName <> "." And strName <> ".." Then colFolders.Add pstrPath
Debug.Print pstrPath & strName
Else
ActiveCell.Offset(0, 1).Value = strName
ActiveCell.Offset(1, 0).Select
End If
strName = Dir
Loop
For Each varFolder In colFolders
Call FileFolderList(varFolder)
Next varFolder
Set colFolders = Nothing
End Sub
This does not appear to be listing the files in the particular subdirectories of G:\Accounts\ I'm trying to search. In Truth, I'm not sure what it is listing.
I also tried
Sub ListSubDirs()
'--------------------------------------------------------------------
'copied from "VBA Developer's Handbook", Ken Getz & Mike Gilbert
'page 661
'c. canter 6/21/07
'--------------------------------------------------------------------
Dim strSubDir, strFile As String
Dim MyAttr As Integer
strPath = "G:\Accounts\"
'Make sure strPath is a directory
'find all the files, including directories
strSubDir = Dir(strPath, vbDirectory)
Do Until strSubDir = ""
If strSubDir <> "." And strSubDir <> ".." Then
ActiveCell.Value = strSubDir
'-------------------------------------------------------------------------
'this section prints all the files in the subdirectory
'from page 656
'-------------------------------------------------------------------------
strSubPath = strPath & strSubDir & "\"
strFile = Dir(strSubPath, vbDirectory)
Do Until strFile = ""
ActiveCell.Offset(1, 0).Select
MyAttr = GetAttr(strFile)
ActiveCell.Offset(0, 1).Value = strFile
strFile = Dir
Loop
'-------------------------------------------------------
ActiveCell.Offset(1, 0).Select
End If
strSubDir = Dir
Loop
End Sub
This routine does not dive into the lower subdirectories.
Any suggestions? Which routine is better? I have to determine if 900 items are in this G:\Accounts\. The plan is to list all the drawings in .pdf file and do a vlookup against the two lists.
Please help. I am really behind the eight ball on this one
Craig Canter
Controller
Elgin IL