Dir or Dir$ Function can be used in Microsoft Visual Basic (Applications) to get the list of directories or files
sDir = Dir$(sPath & "*.xls", vbNormal)
Do Until LenB(sDir) = 0
Set oWB = Workbooks.Open(sPath & sDir)
‘ Do some stuff
oWB.close
sDir = Dir$
Loop
The above will open all Excel Workbooks under a particular directory.
thanks. this code works great!
ReplyDeleteWith subfolders?
ReplyDeleteExcellent example. For Word, just use "Document.Open" instead of "Workbooks.Open". Thanks!
ReplyDeleteWhat is Dir$ and sPath?
ReplyDelete