Thread: DIR
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default DIR

Paul,

I have to confess that on reading your post I thought 'No Way will it do
that' but surprisingly; to me at least, searching for .xls does return .xlsm
files. I don't understand why but here's a workaround which tests the length
of the file extension and ensures that including the . it is 4 characters
long.

Sub LoopThroughDirectory()
x = 1
'Change this to your directory
MyPath = "C:\"
activefile = Dir(MyPath & "*.xls")
Do While activefile < ""
If Len(Mid(activefile, InStr(activefile, "."))) = 4 Then
Cells(x, 1) = activefile
x = x + 1
End If
activefile = Dir()
Loop
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Paul W Smith" wrote:

I want to produce a listing of all the workbooks in a folder what have the
file extension .xls.

When I use Dir(*.xls), I also get all the .xlsm and .xlsb files, which is
not what I want.

Is there a way around this issue?

Paul Smith


.