perform an action on all the files in a folder

  • Thread starter Thread starter Paul Ponzelli
  • Start date Start date
P

Paul Ponzelli

I'd like to perform a series of VBA commands on all the files in a directory
folder, and I need to perform the same commands on each of those files.

In pseudocode, this would be

for each file in drive:path\*.*
[perform operations]
next file

How can I tell VBA to do this?

Thanks in advance,

PP
 
Hi Paul

Check out the Dir function. You call it once with a wildcarded path
expression to return the first file matching the expression, then call it in
a loop with no arguments until it returns a null string. For example:

strFile = Dir("C:\MyPath\*.*")
Do Until Len(strFile) = 0
' do something with strFile
debug.print strFile
' get next file
strFile = Dir
Loop
 
Thanks so much, Graham.

That's what I was looking for.

Paul


Graham Mandeno said:
Hi Paul

Check out the Dir function. You call it once with a wildcarded path
expression to return the first file matching the expression, then call it
in a loop with no arguments until it returns a null string. For example:

strFile = Dir("C:\MyPath\*.*")
Do Until Len(strFile) = 0
' do something with strFile
debug.print strFile
' get next file
strFile = Dir
Loop
--
Good Luck!

Graham Mandeno [Access MVP]
Auckland, New Zealand


Paul Ponzelli said:
I'd like to perform a series of VBA commands on all the files in a
directory
folder, and I need to perform the same commands on each of those files.

In pseudocode, this would be

for each file in drive:path\*.*
[perform operations]
next file

How can I tell VBA to do this?

Thanks in advance,

PP
 
Back
Top