Loop thru a folder

J

JIM

Somewhere there's a routine to loop thru a directory(folder) and print files
in directory. I've searched all the MVP sites and more and cannot find it.
I've got the print routine working -prints pdf or doc files. Can anyone
point me to an example of looping thru a folder?
Thanks
 
D

Douglas J. Steele

Dim strFolder As String
Dim strFile As String

strFolder = "E:\Folder\Subfolder\"
strFile = Dir(strFolder & "*.*")
Do While Len(strFile) > 0
' strFolder & strFile is the full path to the file
strFile = Dir()
Loop

If you want only one file extension, you can use

strFile = Dir(strFolder & "*.pdf")

There's no way, using Dir though, to limit to only pdf and doc extensions.
 
J

JIM

Thanks Douglas. It's working perfect. For those interested here's my code:
Private Sub Option62_Click() 'This subroutine will print or list all
files in a folder
Dim strFolder As String
Dim strFile As String

strFolder = Me.txtPrintAll
strFile = Dir(strFolder & "*.*")

Do While Len(strFile) > 0
Call ExecuteFile(strFolder & strFile, "Print") ' strFolder & strFile is
the full path strFile = Dir()
Loop

Thanks again, JIM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top