> I am looking for a way to automate some of my printing tasks, which, I
> would be able to do if it were not for this problem. I have a directory
[quoted text clipped - 6 lines]
> running into a roadblock. How can I get around the unknown subfolder
> names? Thanks for any help!
This sub will accept your root_folder [in] and an array [in,out]
and will recurse for all files. Change the *.* to *.tiff to filter
for your images. It's very quick.
Public Sub GetDir(ByVal path As String, ByRef Arr As Variant)
Dim sfile As String
Dim sFold() As String
Dim nK As Long
Const sRoutine As String = "GetDir"
On Error GoTo err_GetDir
sfile = Dir(path & "*.*", vbDirectory) '<-- add filter here
'
nK = 0
Do While Len(sfile) > 0
'Debug.Print "sfile=", sfile
If Left$(sfile, 1) Like ("[.%]") Then GoTo DO_NEXT
If (GetAttr(path & sfile) And vbDirectory) > 0 Then
'Debug.Print path & sfile & "\"
ReDim Preserve sFold(0 To nK)
sFold(nK) = path & sfile & "\"
nK = nK + 1
' GetDir path & sfile & "\", Arr
' Debug.Print "succesfully recur"
Else
ReDim Preserve Arr(0 To nJ)
' Debug.Print sfile
Arr(nJ) = LCase(sfile)
nJ = nJ + 1
End If
DO_NEXT:
sfile = Dir(, vbDirectory)
Loop
' handle sub folders
If nK > 0 Then
For nK = 0 To UBound(sFold)
GetDir sFold(nK), Arr
Next
End If
Exit Sub
err_GetDir:
Debug.Print sfile, Err.Number, Err.Description
'Err.Raise Err.Number, "CSort" & "." & sRoutine, Err.Description
End Sub
hth,
tlviewer
Martin Lawrence - 25 Oct 2004 18:53 GMT
I left this info out of my original post and I'm sure it makes a
difference. The folder names are being extracted from an Excel
spreadsheet. What I need this code to do is get the 1st folder name from
the spreadsheet and print what's in that folder, then get the next
folder name from the spreadsheet. This should be repeated until all
items have been printed.
Now--- I tried attaching this code to a command button on the
spreadsheet and the error message I'm getting is "Expected End Sub" and
the debugger is pointing to the first line "Private Sub
commandbutton1_click()". Should this code be placed in a module, or
directly connected to the command button? Also, I assume that with the
code that was provided, all I need to do is insert the path of the root
folder and change the "*.*" to "*.tif"
Martin